public function dump_export_data() { foreach ($this->exporter->get('artefacts') as $artefact) { if (in_array($artefact->get('artefacttype'), PluginArtefactFile::get_artefact_types())) { $this->artefactdata[$artefact->get('id')] = $artefact; } } // Grab all parent folders of all artefacts selected so we can export // the files in their correct folder location if ($this->exporter->get('artefactexportmode') != PluginExport::EXPORT_ALL_ARTEFACTS && $this->artefactdata) { $folderids = array(); foreach (array_keys($this->artefactdata) as $artefactid) { $folderids = array_merge($folderids, array_keys(artefact_get_parents_for_cache($artefactid))); } $folderids = array_unique($folderids); foreach ($folderids as $folderid) { if (!isset($this->artefactdata[$folderid])) { $artefact = artefact_instance_from_id($folderid); // We grabbed all parents of the artefacts in the export, // but not all parents are folders if ($artefact->get('artefacttype') == 'folder') { $this->artefactdata[$folderid] = $artefact; } } } } $this->populate_profileicons(); $this->create_index_for_directory($this->fileroot, 0, null); $this->populate_filedir($this->fileroot, 0, null); }
function pieform_element_wysiwyg_get_headdata() { global $_PIEFORM_WYSIWYGS; if (is_html_editor_enabled() && !empty($_PIEFORM_WYSIWYGS)) { $result = '<script type="application/javascript">' . "\nvar editor_to_focus;" . "\nPieformManager.connect('onsubmit', null, tinyMCE.triggerSave);" . "\nPieformManager.connect('onload', null, function() {\n"; foreach ($_PIEFORM_WYSIWYGS as $editor) { $result .= " tinyMCE.execCommand('mceAddEditor', false, '{$editor}');\n"; $result .= " \$('{$editor}').focus = function() {\n"; $result .= " editor_to_focus = '{$editor}';\n"; $result .= " };\n"; } $result .= "});\nPieformManager.connect('onreply', null, function() {\n"; foreach ($_PIEFORM_WYSIWYGS as $editor) { $result .= " tinyMCE.execCommand('mceRemoveEditor', false, '{$editor}');\n"; } $result .= "});</script>"; safe_require('artefact', 'file'); $strings = PluginArtefactFile::jsstrings('filebrowser'); $jsstrings = ''; foreach ($strings as $section => $sectionstrings) { foreach ($sectionstrings as $s) { $jsstrings .= "strings.{$s}=" . json_encode(get_raw_string($s, $section)) . ';'; } } $headdata = '<script type="application/javascript">' . $jsstrings . '</script>'; return array('tinymce', $result, $headdata); } return array(); }
public function dump_export_data() { global $SESSION; $this->owner = $this->exporter->get('user')->get('id'); foreach ($this->exporter->get('artefacts') as $artefact) { if (in_array($artefact->get('artefacttype'), PluginArtefactFile::get_artefact_types())) { $id = $artefact->get('id'); $this->artefactdata[$id] = $artefact; if ($artefact->get('owner') != $this->owner) { $this->otherfiles[$id] = $id; } } } // Grab all parent folders of all artefacts owned by the exporting user, so we can export // the files in their correct folder location if ($this->exporter->get('artefactexportmode') != PluginExport::EXPORT_ALL_ARTEFACTS && $this->artefactdata) { $folderids = array(); foreach (array_keys($this->artefactdata) as $artefactid) { if (!isset($this->otherfiles[$artefactid])) { $folderids = array_merge($folderids, array_keys(artefact_get_parents_for_cache($artefactid))); } } $folderids = array_unique($folderids); foreach ($folderids as $folderid) { if (!isset($this->artefactdata[$folderid])) { $artefact = artefact_instance_from_id($folderid); // We grabbed all parents of the artefacts in the export, // but not all parents are folders if ($artefact->get('artefacttype') == 'folder') { $this->artefactdata[$folderid] = $artefact; } } } } $this->populate_profileicons(); $this->create_index_for_directory($this->fileroot, 0, null); $this->populate_filedir($this->fileroot, 0, null); // Copy other users' files into the extrafileroot directory foreach ($this->otherfiles as $id) { if (!$this->artefactdata[$id] instanceof ArtefactTypeFile) { continue; } $dest = $this->extrafileroot . $id . '-' . PluginExportHtml::sanitise_path($this->artefactdata[$id]->get('title')); if (!copy($this->artefactdata[$id]->get_path(), $dest)) { $SESSION->add_error_msg(get_string('unabletocopyartefact', 'export', $this->artefactdata[$id]->get('title'))); } } }
function xmldb_artefact_file_upgrade($oldversion = 0) { $status = true; if ($oldversion < 2007010900) { $table = new XMLDBTable('artefact_file_files'); $field = new XMLDBField('adminfiles'); $field->setAttributes(XMLDB_TYPE_INTEGER, 1, false, true, false, null, null, 0); add_field($table, $field); set_field('artefact_file_files', 'adminfiles', 0); // Put all folders into artefact_file_files $folders = get_column_sql("\n SELECT a.id\n FROM {artefact} a\n LEFT OUTER JOIN {artefact_file_files} f ON a.id = f.artefact\n WHERE a.artefacttype = 'folder' AND f.artefact IS NULL"); if ($folders) { foreach ($folders as $folderid) { $data = (object) array('artefact' => $folderid, 'adminfiles' => 0); insert_record('artefact_file_files', $data); } } } if ($oldversion < 2007011800) { // Make sure the default quota is set set_config_plugin('artefact', 'file', 'defaultquota', 10485760); } if ($oldversion < 2007011801) { // Create image table $table = new XMLDBTable('artefact_file_image'); $table->addFieldInfo('artefact', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL); $table->addFieldInfo('width', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL); $table->addFieldInfo('height', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null); $table->addKeyInfo('artefactfk', XMLDB_KEY_FOREIGN, array('artefact'), 'artefact', array('id')); $status = $status && create_table($table); $images = get_column('artefact', 'id', 'artefacttype', 'image'); log_debug(count($images)); require_once get_config('docroot') . 'artefact/lib.php'; foreach ($images as $imageid) { $image = artefact_instance_from_id($imageid); $path = $image->get_path(); $image->set('dirty', false); $data = new StdClass(); $data->artefact = $imageid; if (file_exists($path)) { list($data->width, $data->height) = getimagesize($path); } if (empty($data->width) || empty($data->height)) { $data->width = 0; $data->height = 0; } insert_record('artefact_file_image', $data); } } if ($oldversion < 2007013100) { // Add new tables for file/mime types $table = new XMLDBTable('artefact_file_file_types'); $table->addFieldInfo('description', XMLDB_TYPE_TEXT, 128, null, XMLDB_NOTNULL); $table->addFieldInfo('enabled', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 1); $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('description')); create_table($table); $table = new XMLDBTable('artefact_file_mime_types'); $table->addFieldInfo('mimetype', XMLDB_TYPE_TEXT, 128, null, XMLDB_NOTNULL); $table->addFieldInfo('description', XMLDB_TYPE_TEXT, 128, null, XMLDB_NOTNULL); $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('mimetype')); $table->addKeyInfo('descriptionfk', XMLDB_KEY_FOREIGN, array('description'), 'artefact_file_file_types', array('description')); create_table($table); safe_require('artefact', 'file'); PluginArtefactFile::resync_filetype_list(); } if ($oldversion < 2007021400) { $table = new XMLDBTable('artefact_file_files'); $field = new XMLDBField('oldextension'); $field->setAttributes(XMLDB_TYPE_TEXT); add_field($table, $field); } if ($oldversion < 2007042500) { // migrate everything we had to change to make mysql happy execute_sql("ALTER TABLE {artefact_file_file_types} ALTER COLUMN description TYPE varchar(32)"); execute_sql("ALTER TABLE {artefact_file_mime_types} ALTER COLUMN mimetype TYPE varchar(128)"); execute_sql("ALTER TABLE {artefact_file_mime_types} ALTER COLUMN description TYPE varchar(32)"); } if ($oldversion < 2008091100) { $table = new XMLDBTable('artefact_file_files'); $field = new XMLDBField('fileid'); $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null); add_field($table, $field); execute_sql("UPDATE {artefact_file_files} SET fileid = artefact WHERE NOT size IS NULL"); } if ($oldversion < 2008101602) { $table = new XMLDBTable('artefact_file_files'); $field = new XMLDBField('filetype'); $field->setAttributes(XMLDB_TYPE_TEXT); add_field($table, $field); // Guess mime type for existing files $fileartefacts = get_records_sql_array(' SELECT a.artefacttype, f.artefact, f.oldextension, f.fileid FROM {artefact} a, {artefact_file_files} f WHERE a.id = f.artefact ', array()); require_once get_config('libroot') . 'file.php'; if ($fileartefacts) { foreach ($fileartefacts as $a) { $type = null; if ($a->artefacttype == 'image') { $size = getimagesize(get_config('dataroot') . 'artefact/file/originals/' . $a->fileid % 256 . '/' . $a->fileid); $type = $size['mime']; } else { if ($a->artefacttype == 'profileicon') { $size = getimagesize(get_config('dataroot') . 'artefact/file/profileicons/originals/' . $a->fileid % 256 . '/' . $a->fileid); $type = $size['mime']; } else { if ($a->artefacttype == 'file') { $type = get_mime_type(get_config('dataroot') . 'artefact/file/originals/' . $a->fileid % 256 . '/' . $a->fileid); } } } if ($type) { set_field('artefact_file_files', 'filetype', $type, 'artefact', $a->artefact); } } } delete_records('config', 'field', 'pathtofile'); } if ($oldversion < 2008101701) { if ($data = get_config_plugin('blocktype', 'internalmedia', 'enabledtypes')) { $olddata = unserialize($data); $newdata = array(); foreach ($olddata as $d) { if ($d == 'mov') { $newdata[] = 'quicktime'; } else { if ($d == 'mp4') { $newdata[] = 'mp4_video'; } else { if ($d != 'mpg') { $newdata[] = $d; } } } } set_config_plugin('blocktype', 'internalmedia', 'enabledtypes', serialize($newdata)); } } if ($oldversion < 2009021200) { $table = new XMLDBTable('artefact_file_mime_types'); $key = new XMLDBKey('artefilemimetype_des_fk'); $key->setAttributes(XMLDB_KEY_FOREIGN, array('description'), 'artefact_file_file_types', array('description')); drop_key($table, $key); $table = new XMLDBTable('artefact_file_file_types'); drop_table($table); PluginArtefactFile::resync_filetype_list(); } if ($oldversion < 2009021301) { // IE has been uploading jpegs with the image/pjpeg mimetype, // which is not recognised as an image by the download script. // Fix all existing jpegs in the db: set_field('artefact_file_files', 'filetype', 'image/jpeg', 'filetype', 'image/pjpeg'); // This won't happen again because we now read the contents of the // uploaded file to detect image artefacts, and overwrite the mime // type declared by the browser if we see an image. } if ($oldversion < 2009033000) { if (!get_record('artefact_config', 'plugin', 'file', 'field', 'uploadagreement')) { insert_record('artefact_config', (object) array('plugin' => 'file', 'field' => 'uploadagreement', 'value' => 1)); insert_record('artefact_config', (object) array('plugin' => 'file', 'field' => 'usecustomagreement', 'value' => 1)); } } return $status; }
/** * When the element exists in a form that's present when the page is * first generated the following function gets called and the js file * below will be inserted into the head data. Unfortunately, when * this element is present in a form that gets called in an ajax * request (currently on the view layout page), the .js file is not * loaded and so it's added explicitly to the smarty() call. */ function pieform_element_filebrowser_get_headdata($element) { global $THEME; $headdata = array('<script type="application/javascript" src="' . get_config('wwwroot') . 'artefact/file/js/filebrowser.js"></script>'); if ($element['config']['upload']) { // only add dropzone if filebrowser is allowed to upload $headdata[] = '<script type="application/javascript" src="' . get_config('wwwroot') . 'js/dropzone/dropzone.min.js"></script>'; $headdata[] = '<link href="' . get_config('wwwroot') . 'js/dropzone/css/dropzone.css" type="text/css" rel="stylesheet">'; $headdata[] = '<script type="application/javascript" src="' . get_config('wwwroot') . 'artefact/file/js/filedropzone.js"></script>'; } if ($element['config']['edit']) { // Add switchbox css if filebrowser is allowed to edit require_once get_config('docroot') . 'lib/form/elements/switchbox.php'; $headdata[] = join(' ', pieform_element_switchbox_get_headdata($element)); } $strings = PluginArtefactFile::jsstrings('filebrowser'); $jsstrings = ''; foreach ($strings as $section => $sectionstrings) { foreach ($sectionstrings as $s) { $jsstrings .= "strings.{$s}=" . json_encode(get_raw_string($s, $section)) . ';'; } } $headdata[] = '<script type="application/javascript">' . $jsstrings . '</script>'; $pluginsheets = $THEME->get_url('style/style.css', true, 'artefact/file'); foreach (array_reverse($pluginsheets) as $sheet) { $headdata[] = '<link rel="stylesheet" type="text/css" href="' . $sheet . '">'; } return $headdata; }
function xmldb_artefact_file_upgrade($oldversion = 0) { $status = true; if ($oldversion < 2009033000) { if (!get_record('artefact_config', 'plugin', 'file', 'field', 'uploadagreement')) { insert_record('artefact_config', (object) array('plugin' => 'file', 'field' => 'uploadagreement', 'value' => 1)); insert_record('artefact_config', (object) array('plugin' => 'file', 'field' => 'usecustomagreement', 'value' => 1)); } } if ($oldversion < 2009091700) { execute_sql("DELETE FROM {artefact_file_files} WHERE artefact IN (SELECT id FROM {artefact} WHERE artefacttype = 'folder')"); } if ($oldversion < 2009091701) { $table = new XMLDBTable('artefact_file_files'); $key = new XMLDBKey('artefactpk'); $key->setAttributes(XMLDB_KEY_PRIMARY, array('artefact')); add_key($table, $key); $table = new XMLDBTable('artefact_file_image'); $key = new XMLDBKey('artefactpk'); $key->setAttributes(XMLDB_KEY_PRIMARY, array('artefact')); add_key($table, $key); } if ($oldversion < 2009092300) { insert_record('artefact_installed_type', (object) array('plugin' => 'file', 'name' => 'archive')); // update old files if (function_exists('zip_open')) { $files = get_records_select_array('artefact_file_files', "filetype IN ('application/zip', 'application/x-zip')"); if ($files) { $checked = array(); foreach ($files as $file) { $path = get_config('dataroot') . 'artefact/file/originals/' . $file->fileid % 256 . '/' . $file->fileid; $zip = zip_open($path); if (is_resource($zip)) { $checked[] = $file->artefact; zip_close($zip); } } if (!empty($checked)) { set_field_select('artefact', 'artefacttype', 'archive', "artefacttype = 'file' AND id IN (" . join(',', $checked) . ')', array()); } } } } if ($oldversion < 2010012702) { if ($records = get_records_sql_array("SELECT * FROM {artefact_file_files} WHERE filetype='application/octet-stream'", array())) { require_once 'file.php'; foreach ($records as &$r) { $path = get_config('dataroot') . 'artefact/file/originals/' . $r->fileid % 256 . '/' . $r->fileid; set_field('artefact_file_files', 'filetype', file_mime_type($path), 'fileid', $r->fileid, 'artefact', $r->artefact); } } } if ($oldversion < 2011052500) { // Set default quota to 50MB set_config_plugin('artefact', 'file', 'defaultgroupquota', 52428800); } if ($oldversion < 2011070700) { // Create an images folder for everyone with a profile icon $imagesdir = get_string('imagesdir', 'artefact.file'); $imagesdirdesc = get_string('imagesdirdesc', 'artefact.file'); execute_sql("\n INSERT INTO {artefact} (artefacttype, container, owner, ctime, mtime, atime, title, description, author)\n SELECT 'folder', 1, owner, current_timestamp, current_timestamp, current_timestamp, ?, ?, owner\n FROM {artefact} WHERE owner IS NOT NULL AND artefacttype = 'profileicon'\n GROUP BY owner", array($imagesdir, $imagesdirdesc)); // Put profileicons into the images folder and update the description $profileicondesc = get_string('uploadedprofileicon', 'artefact.file'); if (is_postgres()) { execute_sql("\n UPDATE {artefact}\n SET parent = f.folderid, description = ?\n FROM (\n SELECT owner, MAX(id) AS folderid\n FROM {artefact}\n WHERE artefacttype = 'folder' AND title = ? AND description = ?\n GROUP BY owner\n ) f\n WHERE artefacttype = 'profileicon' AND {artefact}.owner = f.owner", array($profileicondesc, $imagesdir, $imagesdirdesc)); } else { execute_sql("\n UPDATE {artefact}, (\n SELECT owner, MAX(id) AS folderid\n FROM {artefact}\n WHERE artefacttype = 'folder' AND title = ? AND description = ?\n GROUP BY owner\n ) f\n SET parent = f.folderid, description = ?\n WHERE artefacttype = 'profileicon' AND {artefact}.owner = f.owner", array($imagesdir, $imagesdirdesc, $profileicondesc)); } } if ($oldversion < 2011082200) { // video file type if (!get_record('artefact_installed_type', 'plugin', 'file', 'name', 'video')) { insert_record('artefact_installed_type', (object) array('plugin' => 'file', 'name' => 'video')); } // update existing records $videotypes = get_records_sql_array(' SELECT DISTINCT description FROM {artefact_file_mime_types} WHERE mimetype ' . db_ilike() . ' \'%video%\'', array()); if ($videotypes) { $mimetypes = array(); foreach ($videotypes as $type) { $mimetypes[] = $type->description; } $files = get_records_sql_array(' SELECT * FROM {artefact_file_files} WHERE filetype IN ( SELECT mimetype FROM {artefact_file_mime_types} WHERE description IN (' . join(',', array_map('db_quote', array_values($mimetypes))) . ') )', array()); if ($files) { $checked = array(); foreach ($files as $file) { $checked[] = $file->artefact; } if (!empty($checked)) { set_field_select('artefact', 'artefacttype', 'video', "artefacttype = 'file' AND id IN (" . join(',', $checked) . ')', array()); } } } // audio file type if (!get_record('artefact_installed_type', 'plugin', 'file', 'name', 'audio')) { insert_record('artefact_installed_type', (object) array('plugin' => 'file', 'name' => 'audio')); } // update existing records $audiotypes = get_records_sql_array(' SELECT DISTINCT description FROM {artefact_file_mime_types} WHERE mimetype ' . db_ilike() . ' \'%audio%\'', array()); if ($audiotypes) { $mimetypes = array(); foreach ($audiotypes as $type) { $mimetypes[] = $type->description; } $files = get_records_sql_array(' SELECT * FROM {artefact_file_files} WHERE filetype IN ( SELECT mimetype FROM {artefact_file_mime_types} WHERE description IN (' . join(',', array_map('db_quote', array_values($mimetypes))) . ') )', array()); if ($files) { $checked = array(); foreach ($files as $file) { $checked[] = $file->artefact; } if (!empty($checked)) { set_field_select('artefact', 'artefacttype', 'audio', "artefacttype = 'file' AND id IN (" . join(',', $checked) . ')', array()); } } } } if ($oldversion < 2012050400) { if (!get_record('artefact_config', 'plugin', 'file', 'field', 'resizeonuploadenable')) { insert_record('artefact_config', (object) array('plugin' => 'file', 'field' => 'resizeonuploadenable', 'value' => 0)); insert_record('artefact_config', (object) array('plugin' => 'file', 'field' => 'resizeonuploaduseroption', 'value' => 0)); insert_record('artefact_config', (object) array('plugin' => 'file', 'field' => 'resizeonuploadmaxheight', 'value' => get_config('imagemaxheight'))); insert_record('artefact_config', (object) array('plugin' => 'file', 'field' => 'resizeonuploadmaxwidth', 'value' => get_config('imagemaxwidth'))); } } if ($oldversion < 2012092400) { $basepath = get_config('dataroot') . "artefact/file/originals/"; try { check_dir_exists($basepath, true); } catch (Exception $e) { throw new SystemException("Failed to create " . $basepath); } $baseiter = new DirectoryIterator($basepath); foreach ($baseiter as $dir) { if ($dir->isDot()) { continue; } $dirpath = $dir->getPath() . '/' . $dir->getFilename(); $fileiter = new DirectoryIterator($dirpath); foreach ($fileiter as $file) { if ($file->isDot()) { continue; } if (!$file->isFile()) { log_error("Something was wrong about the dataroot in artefact/file/originals/{$dir}. Unexpected folder {$file}"); continue; } chmod($file->getPathname(), $file->getPerms() & 0666); } } } if ($oldversion < 2013031200) { // Update MIME types for Microsoft video files: avi, asf, wm, and wmv update_record('artefact_file_mime_types', (object) array('mimetype' => 'video/x-ms-asf', 'description' => 'asf'), (object) array('mimetype' => 'video/x-ms-asf')); update_record('artefact_file_mime_types', (object) array('mimetype' => 'video/x-ms-wm', 'description' => 'wm'), (object) array('mimetype' => 'video/x-ms-wm')); update_record('artefact_file_mime_types', (object) array('mimetype' => 'video/x-ms-wmv', 'description' => 'wmv'), (object) array('mimetype' => 'video/x-ms-wmv')); } if ($oldversion < 2014040800) { ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'audio/aac'), (object) array('mimetype' => 'audio/aac', 'description' => 'aac')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/msaccess'), (object) array('mimetype' => 'application/msaccess', 'description' => 'accdb')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'shockwave/director'), (object) array('mimetype' => 'shockwave/director', 'description' => 'cct')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/x-csh'), (object) array('mimetype' => 'application/x-csh', 'description' => 'cs')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'text/css'), (object) array('mimetype' => 'text/css', 'description' => 'css')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'text/csv'), (object) array('mimetype' => 'text/csv', 'description' => 'csv')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'video/x-dv'), (object) array('mimetype' => 'video/x-dv', 'description' => 'dv')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'), (object) array('mimetype' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'description' => 'docx')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.ms-word.document.macroEnabled.12'), (object) array('mimetype' => 'application/vnd.ms-word.document.macroEnabled.12', 'description' => 'docm')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template'), (object) array('mimetype' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template', 'description' => 'dotx')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.ms-word.template.macroEnabled.12'), (object) array('mimetype' => 'application/vnd.ms-word.template.macroEnabled.12', 'description' => 'dotm')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/x-director'), (object) array('mimetype' => 'application/x-director', 'description' => 'dcr')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/epub+zip'), (object) array('mimetype' => 'application/epub+zip', 'description' => 'epub')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/x-smarttech-notebook'), (object) array('mimetype' => 'application/x-smarttech-notebook', 'description' => 'gallery')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/mac-binhex40'), (object) array('mimetype' => 'application/mac-binhex40', 'description' => 'hqx')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'text/x-component'), (object) array('mimetype' => 'text/x-component', 'description' => 'htc')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/xhtml+xml'), (object) array('mimetype' => 'application/xhtml+xml', 'description' => 'xhtml')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'image/vnd.microsoft.icon'), (object) array('mimetype' => 'image/vnd.microsoft.icon', 'description' => 'ico')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'text/calendar'), (object) array('mimetype' => 'text/calendar', 'description' => 'ics')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/inspiration'), (object) array('mimetype' => 'application/inspiration', 'description' => 'isf')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/inspiration.template'), (object) array('mimetype' => 'application/inspiration.template', 'description' => 'ist')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/java-archive'), (object) array('mimetype' => 'application/java-archive', 'description' => 'jar')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/x-java-jnlp-file'), (object) array('mimetype' => 'application/x-java-jnlp-file', 'description' => 'jnlp')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.moodle.backup'), (object) array('mimetype' => 'application/vnd.moodle.backup', 'description' => 'mbz')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/x-msaccess'), (object) array('mimetype' => 'application/x-msaccess', 'description' => 'mdb')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'message/rfc822'), (object) array('mimetype' => 'message/rfc822', 'description' => 'mht')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.moodle.profiling'), (object) array('mimetype' => 'application/vnd.moodle.profiling', 'description' => 'mpr')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.oasis.opendocument.graphics-template'), (object) array('mimetype' => 'application/vnd.oasis.opendocument.graphics-template', 'description' => 'otg')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.oasis.opendocument.presentation-template'), (object) array('mimetype' => 'application/vnd.oasis.opendocument.presentation-template', 'description' => 'otp')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.oasis.opendocument.spreadsheet-template'), (object) array('mimetype' => 'application/vnd.oasis.opendocument.spreadsheet-template', 'description' => 'ots')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'audio/ogg'), (object) array('mimetype' => 'audio/ogg', 'description' => 'oga')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'video/ogg'), (object) array('mimetype' => 'video/ogg', 'description' => 'ogv')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'image/pict'), (object) array('mimetype' => 'image/pict', 'description' => 'pct')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation'), (object) array('mimetype' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', 'description' => 'pptx')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12'), (object) array('mimetype' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12', 'description' => 'pptm')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.openxmlformats-officedocument.presentationml.template'), (object) array('mimetype' => 'application/vnd.openxmlformats-officedocument.presentationml.template', 'description' => 'potx')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.ms-powerpoint.template.macroEnabled.12'), (object) array('mimetype' => 'application/vnd.ms-powerpoint.template.macroEnabled.12', 'description' => 'potm')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12'), (object) array('mimetype' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12', 'description' => 'ppam')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow'), (object) array('mimetype' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow', 'description' => 'ppsx')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12'), (object) array('mimetype' => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12', 'description' => 'ppsm')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'audio/x-realaudio-plugin'), (object) array('mimetype' => 'audio/x-realaudio-plugin', 'description' => 'ra')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'audio/x-pn-realaudio-plugin'), (object) array('mimetype' => 'audio/x-pn-realaudio-plugin', 'description' => 'ram')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.rn-realmedia-vbr'), (object) array('mimetype' => 'application/vnd.rn-realmedia-vbr', 'description' => 'rmvb')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'text/richtext'), (object) array('mimetype' => 'text/richtext', 'description' => 'rtx')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/x-stuffit'), (object) array('mimetype' => 'application/x-stuffit', 'description' => 'sit')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/smil'), (object) array('mimetype' => 'application/smil', 'description' => 'smi')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'image/svg+xml'), (object) array('mimetype' => 'image/svg+xml', 'description' => 'svg')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.sun.xml.writer'), (object) array('mimetype' => 'application/vnd.sun.xml.writer', 'description' => 'sxw')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.sun.xml.writer.template'), (object) array('mimetype' => 'application/vnd.sun.xml.writer.template', 'description' => 'stw')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.sun.xml.calc'), (object) array('mimetype' => 'application/vnd.sun.xml.calc', 'description' => 'sxc')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.sun.xml.calc.template'), (object) array('mimetype' => 'application/vnd.sun.xml.calc.template', 'description' => 'stc')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.sun.xml.draw'), (object) array('mimetype' => 'application/vnd.sun.xml.draw', 'description' => 'sxd')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.sun.xml.draw.template'), (object) array('mimetype' => 'application/vnd.sun.xml.draw.template', 'description' => 'std')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.sun.xml.impress'), (object) array('mimetype' => 'application/vnd.sun.xml.impress', 'description' => 'sxi')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.sun.xml.impress.template'), (object) array('mimetype' => 'application/vnd.sun.xml.impress.template', 'description' => 'sti')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.sun.xml.writer.global'), (object) array('mimetype' => 'application/vnd.sun.xml.writer.global', 'description' => 'sxg')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.sun.xml.math'), (object) array('mimetype' => 'application/vnd.sun.xml.math', 'description' => 'sxm')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'image/tiff'), (object) array('mimetype' => 'image/tiff', 'description' => 'tif')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/x-tex'), (object) array('mimetype' => 'application/x-tex', 'description' => 'tex')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/x-texinfo'), (object) array('mimetype' => 'application/x-texinfo', 'description' => 'texi')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'text/tab-separated-values'), (object) array('mimetype' => 'text/tab-separated-values', 'description' => 'tsv')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'video/webm'), (object) array('mimetype' => 'video/webm', 'description' => 'webm')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.ms-excel'), (object) array('mimetype' => 'application/vnd.ms-excel', 'description' => 'xls')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'), (object) array('mimetype' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'description' => 'xlsx')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.ms-excel.sheet.macroEnabled.12'), (object) array('mimetype' => 'application/vnd.ms-excel.sheet.macroEnabled.12', 'description' => 'xlsm')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template'), (object) array('mimetype' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template', 'description' => 'xltx')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.ms-excel.template.macroEnabled.12'), (object) array('mimetype' => 'application/vnd.ms-excel.template.macroEnabled.12', 'description' => 'xltm')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12'), (object) array('mimetype' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12', 'description' => 'xlsb')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.ms-excel.addin.macroEnabled.12'), (object) array('mimetype' => 'application/vnd.ms-excel.addin.macroEnabled.12', 'description' => 'xlam')); ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/xml'), (object) array('mimetype' => 'application/xml', 'description' => 'xml')); } if ($oldversion < 2014051200) { require_once get_config('docroot') . '/lib/file.php'; $mimetypes = get_records_assoc('artefact_file_mime_types', '', '', '', 'description,mimetype'); // Re-examine only those files where their current identified mimetype is // different from how we would identify their mimetype based on file extension $rs = get_recordset_sql(' select a.id, aff.oldextension, aff.filetype from {artefact} a inner join {artefact_file_files} aff on a.id = aff.artefact where a.artefacttype = \'archive\' and not exists ( select 1 from {artefact_file_mime_types} afmt where afmt.description = aff.oldextension and afmt.mimetype = aff.filetype ) order by a.id '); $total = 0; $done = 0; while ($zf = $rs->FetchRow()) { if ($done % 100 == 0) { log_debug('Verifying filetypes: ' . $done . '/' . $rs->RecordCount()); } $done++; $file = artefact_instance_from_id($zf['id']); $path = $file->get_path(); // Check what our improved file detection system thinks it is $guess = file_mime_type($path, 'foo.' . $zf['oldextension']); if ($guess != 'application/octet-stream') { $data = new stdClass(); $data->filetype = $data->guess = $guess; foreach (array('video', 'audio', 'archive') as $artefacttype) { $classname = 'ArtefactType' . ucfirst($artefacttype); if (call_user_func_array(array($classname, 'is_valid_file'), array($file->get_path(), &$data))) { set_field('artefact', 'artefacttype', $artefacttype, 'id', $zf['id']); set_field('artefact_file_files', 'filetype', $data->filetype, 'artefact', $zf['id']); continue 2; } } // It wasn't any of those special ones, so just make it a normal file artefact set_field('artefact', 'artefacttype', 'file', 'id', $zf['id']); set_field('artefact_file_files', 'filetype', $data->filetype, 'artefact', $zf['id']); } } log_debug('Verifying filetypes: ' . $done . '/' . $rs->RecordCount()); $rs->Close(); } if ($oldversion < 2014060900) { $events = array((object) array('plugin' => 'file', 'event' => 'saveartefact', 'callfunction' => 'eventlistener_savedeleteartefact'), (object) array('plugin' => 'file', 'event' => 'deleteartefact', 'callfunction' => 'eventlistener_savedeleteartefact'), (object) array('plugin' => 'file', 'event' => 'deleteartefacts', 'callfunction' => 'eventlistener_savedeleteartefact'), (object) array('plugin' => 'file', 'event' => 'updateuser', 'callfunction' => 'eventlistener_savedeleteartefact')); foreach ($events as $event) { ensure_record_exists('artefact_event_subscription', $event, $event); } PluginArtefactFile::set_quota_triggers(); } if ($oldversion < 2014061000) { // Remove the not needed quota notify on update config trigger from previous update if (is_postgres()) { $sql = 'DROP TRIGGER IF EXISTS {unmark_quota_exeed_notified_on_update_setting_trigger} ON {artefact_config};'; } else { $sql = 'DROP TRIGGER IF EXISTS {unmark_quota_exeed_notified_on_update_setting_trigger};'; } execute_sql($sql); } if ($oldversion < 2014111200) { // Create embedded images table $table = new XMLDBTable('artefact_file_embedded'); $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE); $table->addFieldInfo('fileid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL); $table->addFieldInfo('resourcetype', XMLDB_TYPE_CHAR, '100', XMLDB_UNSIGNED, XMLDB_NOTNULL); $table->addFieldInfo('resourceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL); $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id')); $table->addKeyInfo('artefactfk', XMLDB_KEY_FOREIGN, array('fileid'), 'artefact', array('id')); $status = $status && create_table($table); } if ($oldversion < 2015101900) { log_debug('Need to consolidate "textbox" and "editnote" embedded resource types as they are in fact the same thing'); if ($records = get_records_sql_array('SELECT * FROM {artefact_file_embedded} WHERE resourcetype IN (?, ?)', array('editnote', 'textbox'))) { $newrecords = array(); // Turn the results into something easier to check against foreach ($records as $k => $v) { $newrecords[$v->resourcetype . '_' . $v->resourceid . '_' . $v->fileid] = $v; } foreach ($newrecords as $nk => $nv) { // need to sort out the 'editnote' options if (preg_match('/^editnote_(.*)$/', $nk, $match)) { // Check to see if there is a corresponding 'textbox' one - if not we need to make one if (!array_key_exists('textbox_' . $match[1], $newrecords)) { insert_record('artefact_file_embedded', (object) array('fileid' => $nv->fileid, 'resourcetype' => 'textbox', 'resourceid' => $nv->resourceid)); } // now delete the 'editnote' one delete_records('artefact_file_embedded', 'id', $nv->id); } } } } return $status; }
/** * Retrieve file list in a folder * @global object $REMOTEWWWROOT * @param string $username * @param integer $folderid folder to browse * @return array The complete folder path + list of files for a specific Mahara folder */ function get_folder_files($username, $folderid) { global $REMOTEWWWROOT; //check that the user exists list($user, $authinstance) = find_remote_user($username, $REMOTEWWWROOT); if (!$user) { throw new ExportException("Could not find user {$username} for {$REMOTEWWWROOT}"); } $list = array(); safe_require('artefact', 'file'); $filetypes = array_diff(PluginArtefactFile::get_artefact_types(), array('profileicon')); foreach ($filetypes as $k => $v) { if ($v == 'folder') { unset($filetypes[$k]); } } $filetypesql = "('" . join("','", $filetypes) . "')"; $ownersql = artefact_owner_sql($user->id); $folderpath = array(); //the complete folder path (some client could need it) if (!empty($folderid)) { $pathsql = " AND parent = {$folderid}"; //build the path $parentids = artefact_get_parents_for_cache($folderid); //the closest parent is on the first key //the further parent is on the last key foreach ($parentids as $id => $dump) { $artefact = get_record('artefact', 'id', $id); array_unshift($folderpath, array('path' => $artefact->id, 'name' => $artefact->title)); } } else { $pathsql = "AND parent IS NULL"; } array_unshift($folderpath, array('path' => null, 'name' => 'Root')); //retrieve folders and files of a specific Mahara folder $list = array('files' => get_records_select_array('artefact', "artefacttype IN {$filetypesql} AND {$ownersql} {$pathsql}", array(), 'title'), 'folders' => get_records_select_array('artefact', "artefacttype = 'folder' AND {$ownersql} {$pathsql}", array(), 'title')); return array($folderpath, $list); }
/** * 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); } }
/** * Return a unique artefact title for a given owner & parent. * * Try to add digits before the filename extension: If the desired * title contains a ".", add "." plus digits before the final ".", * otherwise append "." and digits. * * @param string $desired * @param integer $parent * @param integer $owner * @param integer $group * @param string $institution */ public static function get_new_file_title($desired, $parent, $owner = null, $group = null, $institution = null) { $bits = split('\\.', $desired); if (count($bits) > 1 && preg_match('/[^0-9]/', end($bits))) { $start = join('.', array_slice($bits, 0, count($bits) - 1)); $end = '.' . end($bits); } else { $start = $desired; $end = ''; } $where = $parent ? "parent = {$parent}" : 'parent IS NULL'; $where .= ' AND ' . artefact_owner_sql($owner, $group, $institution); $taken = get_column_sql("\n SELECT title FROM {artefact}\n WHERE artefacttype IN ('" . join("','", array_diff(PluginArtefactFile::get_artefact_types(), array('profileicon'))) . "')\n AND title LIKE ? || '%' || ? AND " . $where, array($start, $end)); $taken = array_flip($taken); $i = 0; $newname = $start . $end; while (isset($taken[$newname])) { $i++; $newname = $start . '.' . $i . $end; } return $newname; }
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; }
/** * When the element exists in a form that's present when the page is * first generated the following function gets called and the js file * below will be inserted into the head data. Unfortunately, when * this element is present in a form that gets called in an ajax * request (currently on the view layout page), the .js file is not * loaded and so it's added explicitly to the smarty() call. */ function pieform_element_filebrowser_get_headdata($element) { global $THEME; $headdata = array('<script type="text/javascript" src="' . get_config('wwwroot') . 'artefact/file/js/filebrowser.js"></script>'); $strings = PluginArtefactFile::jsstrings('filebrowser'); $jsstrings = ''; foreach ($strings as $section => $sectionstrings) { foreach ($sectionstrings as $s) { $jsstrings .= "strings.{$s}=" . json_encode(get_raw_string($s, $section)) . ';'; } } $headdata[] = '<script type="text/javascript">' . $jsstrings . '</script>'; $pluginsheets = $THEME->get_url('style/style.css', true, 'artefact/file'); foreach (array_reverse($pluginsheets) as $sheet) { $headdata[] = '<link rel="stylesheet" type="text/css" href="' . $sheet . '">'; } return $headdata; }
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']))); } } } } }
$options = array(); if (empty($embedded)) { $options['forcedownload'] = true; } // Clean up the temp directory before creating anymore zip files. zip_clean_temp_dir(); // Home folder if ($folderid === 0) { if (function_exists('zip_open')) { global $USER; $userid = $USER->get('id'); $select = ' SELECT a.id, a.artefacttype, a.title'; $from = ' FROM {artefact} a'; $in = "('" . join("','", PluginArtefactFile::get_artefact_types()) . "')"; $where = "\n WHERE artefacttype IN {$in}"; $phvals = array(); if ($institution) { if ($institution == 'mahara' && !$USER->get('admin')) { // If non-admins are browsing site files, only let them see the public folder & its contents $publicfolder = ArtefactTypeFolder::admin_public_folder_id(); $where .= ' AND (a.path = ? OR a.path LIKE ?)'; $phvals = array("/{$publicfolder}", db_like_escape("/{$publicfolder}/") . '%'); } $where .= ' AND a.institution = ? AND a.owner IS NULL'; $phvals[] = $institution; } else { if ($groupid) {
/** * When the element exists in a form that's present when the page is * first generated the following function gets called and the js file * below will be inserted into the head data. Unfortunately, when * this element is present in a form that gets called in an ajax * request (currently on the view layout page), the .js file is not * loaded and so it's added explicitly to the smarty() call. */ function pieform_element_filebrowser_get_headdata($element) { $headdata = array('<script type="text/javascript" src="' . get_config('wwwroot') . 'artefact/file/js/filebrowser.js"></script>'); $strings = PluginArtefactFile::jsstrings('filebrowser'); $jsstrings = ''; foreach ($strings as $section => $sectionstrings) { foreach ($sectionstrings as $s) { $jsstrings .= "strings.{$s}=" . json_encode(get_raw_string($s, $section)) . ';'; } } $headdata[] = '<script type="text/javascript">' . $jsstrings . '</script>'; return $headdata; }