/** * Test method get_supported_extensions() */ public function test_supported_extensions() { $nativeextensions = file_get_typegroup('extension', 'html_video'); // Make sure that the list of extensions from the setting is exactly the same as html_video group. $player = new media_html5video_plugin(); $this->assertEmpty(array_diff($player->get_supported_extensions(), $nativeextensions)); $this->assertEmpty(array_diff($nativeextensions, $player->get_supported_extensions())); }
/** * Test method get_supported_extensions() */ public function test_supported_extensions() { global $CFG; require_once $CFG->libdir . '/filelib.php'; $nativeextensions = file_get_typegroup('extension', 'html_audio'); // Make sure that the list of extensions from the setting is exactly the same as html_audio group. $player = new media_html5audio_plugin(); $this->assertEmpty(array_diff($player->get_supported_extensions(), $nativeextensions)); $this->assertEmpty(array_diff($nativeextensions, $player->get_supported_extensions())); }
/** * Test method get_supported_extensions() */ public function test_supported_extensions() { $nativeextensions = array_merge(file_get_typegroup('extension', 'html_video'), file_get_typegroup('extension', 'html_audio')); set_config('useflash', 0, 'media_videojs'); // Make sure that the list of extensions from the setting is filtered to HTML5 natively supported extensions. $player = new media_videojs_plugin(); $this->assertNotEmpty($player->get_supported_extensions()); $this->assertTrue(in_array('.mp3', $player->get_supported_extensions())); $this->assertEmpty(array_diff($player->get_supported_extensions(), $nativeextensions)); // Try to set the audioextensions to something non-native (.ra) and make sure it is not returned as supported. set_config('audioextensions', '.mp3,.wav,.ra', 'media_videojs'); $player = new media_videojs_plugin(); $this->assertNotEmpty($player->get_supported_extensions()); $this->assertTrue(in_array('.mp3', $player->get_supported_extensions())); $this->assertFalse(in_array('.ra', $player->get_supported_extensions())); $this->assertEmpty(array_diff($player->get_supported_extensions(), $nativeextensions)); }
/** * Provide repository instance information for Ajax * * @return stdClass */ public final function get_meta() { global $CFG, $OUTPUT; $meta = new stdClass(); $meta->id = $this->id; $meta->name = format_string($this->get_name()); $meta->type = $this->get_typename(); $meta->icon = $OUTPUT->pix_url('icon', 'repository_' . $meta->type)->out(false); $meta->supported_types = file_get_typegroup('extension', $this->supported_filetypes()); $meta->return_types = $this->supported_returntypes(); $meta->sortorder = $this->options['sortorder']; return $meta; }
/** * Checks if mimetype $mimetype belongs to one of the groups $groups * * @see get_mimetypes_array() * @param string $mimetype * @param string|array $groups one group or array of groups to check * @return bool */ function file_mimetype_in_typegroup($mimetype, $groups) { return !empty($mimetype) && in_array($mimetype, file_get_typegroup('type', $groups)); }
/** * Returns options to use in course overviewfiles filemanager * * @param null|stdClass|course_in_list|int $course either object that has 'id' property or just the course id; * may be empty if course does not exist yet (course create form) * @return array|null array of options such as maxfiles, maxbytes, accepted_types, etc. * or null if overviewfiles are disabled */ function course_overviewfiles_options($course) { global $CFG; if (empty($CFG->courseoverviewfileslimit)) { return null; } $accepted_types = preg_split('/\\s*,\\s*/', trim($CFG->courseoverviewfilesext), -1, PREG_SPLIT_NO_EMPTY); if (in_array('*', $accepted_types) || empty($accepted_types)) { $accepted_types = '*'; } else { // Since config for $CFG->courseoverviewfilesext is a text box, human factor must be considered. // Make sure extensions are prefixed with dot unless they are valid typegroups foreach ($accepted_types as $i => $type) { if (substr($type, 0, 1) !== '.') { require_once $CFG->libdir . '/filelib.php'; if (!count(file_get_typegroup('extension', $type))) { // It does not start with dot and is not a valid typegroup, this is most likely extension. $accepted_types[$i] = '.' . $type; $corrected = true; } } } if (!empty($corrected)) { set_config('courseoverviewfilesext', join(',', $accepted_types)); } } $options = array('maxfiles' => $CFG->courseoverviewfileslimit, 'maxbytes' => $CFG->maxbytes, 'subdirs' => 0, 'accepted_types' => $accepted_types); if (!empty($course->id)) { $options['context'] = context_course::instance($course->id); } else { if (is_int($course) && $course > 0) { $options['context'] = context_course::instance($course); } } return $options; }
public function get_supported_extensions() { global $CFG; require_once $CFG->libdir . '/filelib.php'; return file_get_typegroup('extension', 'html_audio'); }
/** * Register the ability to handle drag and drop file uploads * @return array containing details of the files / types the mod can handle */ function label_dndupload_register() { $strdnd = get_string('dnduploadlabel', 'mod_label'); if (get_config('label', 'dndmedia')) { $mediaextensions = file_get_typegroup('extension', 'web_image'); $files = array(); foreach ($mediaextensions as $extn) { $extn = trim($extn, '.'); $files[] = array('extension' => $extn, 'message' => $strdnd); } $ret = array('files' => $files); } else { $ret = array(); } $strdndtext = get_string('dnduploadlabeltext', 'mod_label'); return array_merge($ret, array('types' => array(array('identifier' => 'text/html', 'message' => $strdndtext, 'noname' => true), array('identifier' => 'text', 'message' => $strdndtext, 'noname' => true)))); }
protected function definition() { global $CFG; $mform = $this->_form; $version = $this->_customdata['version']; $format = $this->_customdata['format']; if (empty($this->_customdata['contextid'])) { // Hack alert // This is being done ONLY to aid those who may have created there own wiki pages. It should be removed sometime // after the release of 2.3 (not creating an issue because this whole thing should be reviewed) debugging('You must always provide mod_wiki_edit_form with a contextid in its custom data', DEBUG_DEVELOPER); global $PAGE; $contextid = $PAGE->context->id; } else { $contextid = $this->_customdata['contextid']; } if (isset($this->_customdata['pagetitle'])) { // Page title must be formatted properly here as this is output and not an element. $pagetitle = get_string('editingpage', 'wiki', format_string($this->_customdata['pagetitle'], true, array('context' => get_context_instance_by_id($contextid, MUST_EXIST)))); } else { $pagetitle = get_string('editing', 'wiki'); } //editor $mform->addElement('header', 'general', $pagetitle); $fieldname = get_string('format' . $format, 'wiki'); if ($format != 'html') { // Use wiki editor $extensions = file_get_typegroup('extension', 'web_image'); $fs = get_file_storage(); $tree = $fs->get_area_tree($contextid, 'mod_wiki', $this->_customdata['filearea'], $this->_customdata['fileitemid']); $files = array(); foreach ($tree['files'] as $file) { $filename = $file->get_filename(); foreach ($extensions as $ext) { if (preg_match('#' . $ext . '$#i', $filename)) { $files[] = $filename; } } } $mform->addElement('wikieditor', 'newcontent', $fieldname, array('cols' => 100, 'rows' => 20, 'wiki_format' => $format, 'files' => $files)); $mform->addHelpButton('newcontent', 'format' . $format, 'wiki'); $mform->setType('newcontent', PARAM_RAW); // processed by trust text or cleaned before the display } else { $mform->addElement('editor', 'newcontent_editor', $fieldname, null, page_wiki_edit::$attachmentoptions); $mform->addHelpButton('newcontent_editor', 'formathtml', 'wiki'); $mform->setType('newcontent_editor', PARAM_RAW); // processed by trust text or cleaned before the display } //hiddens if ($version >= 0) { $mform->addElement('hidden', 'version', $version); $mform->setType('version', PARAM_FLOAT); } $mform->addElement('hidden', 'contentformat', $format); $mform->setType('contentformat', PARAM_ALPHANUMEXT); if (!empty($CFG->usetags)) { $tags = !isset($this->_customdata['tags']) ? "" : $this->_customdata['tags']; $mform->addElement('header', 'tagshdr', get_string('tags', 'tag')); $mform->addElement('tags', 'tags', get_string('tags')); $mform->setDefault('tags', $tags); $mform->setType('tags', PARAM_TEXT); } $buttongroup = array(); $buttongroup[] = $mform->createElement('submit', 'editoption', get_string('save', 'wiki'), array('id' => 'save')); $buttongroup[] = $mform->createElement('submit', 'editoption', get_string('preview'), array('id' => 'preview')); $buttongroup[] = $mform->createElement('submit', 'editoption', get_string('cancel'), array('id' => 'cancel')); $mform->addGroup($buttongroup, 'buttonar', '', array(' '), false); $mform->closeHeaderBefore('buttonar'); }
/** * Return presentation documents mimetypes * * @return array presentation document mimetypes */ public static function mimetypes() { return file_get_typegroup('type', 'presentation'); }
public function get_supported_extensions() { global $CFG; require_once $CFG->libdir . '/filelib.php'; if ($this->extensions === null) { $filetypes = preg_split('/\\s*,\\s*/', strtolower(trim(get_config('media_videojs', 'videoextensions') . ',' . get_config('media_videojs', 'audioextensions')))); $this->extensions = file_get_typegroup('extension', $filetypes); if ($this->extensions && !get_config('media_videojs', 'useflash')) { // If Flash is disabled only return extensions natively supported by browsers. $nativeextensions = array_merge(file_get_typegroup('extension', 'html_video'), file_get_typegroup('extension', 'html_audio')); $this->extensions = array_intersect($this->extensions, $nativeextensions); } } return $this->extensions; }
/** * Register the ability to handle drag and drop file uploads * @return array containing details of the files / types the mod can handle */ function label_dndupload_register() { if (get_config('label', 'dndmedia')) { $mediaextensions = file_get_typegroup('extension', 'web_image'); $strdnd = get_string('dnduploadlabel', 'mod_label'); $files = array(); foreach ($mediaextensions as $extn) { $extn = trim($extn, '.'); $files[] = array('extension' => $extn, 'message' => $strdnd); } return array('files' => $files); } else { return array(); } }