本文整理汇总了PHP中workshop::normalize_file_extensions方法的典型用法代码示例。如果您正苦于以下问题:PHP workshop::normalize_file_extensions方法的具体用法?PHP workshop::normalize_file_extensions怎么用?PHP workshop::normalize_file_extensions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类workshop
的用法示例。
在下文中一共展示了workshop::normalize_file_extensions方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validation
function validation($data, $files)
{
global $CFG, $USER, $DB;
$errors = parent::validation($data, $files);
if (empty($data['id']) and empty($data['example'])) {
// make sure there is no submission saved meanwhile from another browser window
$sql = "SELECT COUNT(s.id)\n FROM {workshop_submissions} s\n JOIN {workshop} w ON (s.workshopid = w.id)\n JOIN {course_modules} cm ON (w.id = cm.instance)\n JOIN {modules} m ON (m.name = 'workshop' AND m.id = cm.module)\n WHERE cm.id = ? AND s.authorid = ? AND s.example = 0";
if ($DB->count_records_sql($sql, array($data['cmid'], $USER->id))) {
$errors['title'] = get_string('err_multiplesubmissions', 'mod_workshop');
}
}
if (isset($data['attachment_filemanager']) and isset($this->_customdata['workshop']->submissionfiletypes)) {
$whitelist = workshop::normalize_file_extensions($this->_customdata['workshop']->submissionfiletypes);
if ($whitelist) {
$draftfiles = file_get_drafarea_files($data['attachment_filemanager']);
if ($draftfiles) {
$wrongfiles = array();
foreach ($draftfiles->list as $file) {
if (!workshop::is_allowed_file_type($file->filename, $whitelist)) {
$wrongfiles[] = $file->filename;
}
}
if ($wrongfiles) {
$a = array('whitelist' => workshop::clean_file_extensions($whitelist), 'wrongfiles' => implode(', ', $wrongfiles));
$errors['attachment_filemanager'] = get_string('err_wrongfileextension', 'mod_workshop', $a);
}
}
}
}
return $errors;
}
示例2: test_normalize_file_extensions
/**
* Test normalizing list of extensions.
*/
public function test_normalize_file_extensions()
{
$this->resetAfterTest(true);
$this->assertSame(['.odt'], workshop::normalize_file_extensions('odt'));
$this->assertSame(['.odt'], workshop::normalize_file_extensions('.odt'));
$this->assertSame(['.odt'], workshop::normalize_file_extensions('.ODT'));
$this->assertSame(['.doc', '.jpg', '.mp3'], workshop::normalize_file_extensions('doc, jpg, mp3'));
$this->assertSame(['.doc', '.jpg', '.mp3'], workshop::normalize_file_extensions(['.doc', '.jpg', '.mp3']));
$this->assertSame(['.doc', '.jpg', '.mp3'], workshop::normalize_file_extensions('doc, *.jpg, mp3'));
$this->assertSame(['.doc', '.jpg', '.mp3'], workshop::normalize_file_extensions(['doc ', ' JPG ', '.mp3']));
$this->assertSame(['.rtf', '.pdf', '.docx'], workshop::normalize_file_extensions("RTF,.pdf\n...DocX,,,;\rPDF\trtf ...Rtf"));
$this->assertSame(['.tgz', '.tar.gz'], workshop::normalize_file_extensions('tgz,TAR.GZ tar.gz .tar.gz tgz TGZ'));
$this->assertSame(['.notebook'], workshop::normalize_file_extensions('"Notebook":notebook;NOTEBOOK;,\'NoTeBook\''));
$this->assertSame([], workshop::normalize_file_extensions(''));
$this->assertSame([], workshop::normalize_file_extensions([]));
$this->assertSame(['.0'], workshop::normalize_file_extensions(0));
$this->assertSame(['.0'], workshop::normalize_file_extensions('0'));
$this->assertSame(['.odt'], workshop::normalize_file_extensions('*.odt'));
$this->assertSame([], workshop::normalize_file_extensions('.'));
$this->assertSame(['.foo'], workshop::normalize_file_extensions('. foo'));
$this->assertSame([], workshop::normalize_file_extensions('*'));
$this->assertSame([], workshop::normalize_file_extensions('*~'));
$this->assertSame(['.pdf', '.ps'], workshop::normalize_file_extensions('* pdf *.ps foo* *bar .r??'));
}
示例3: validation
/**
* Validate assessment form data.
*
* @param array $data
* @param array $files
* @return array
*/
public function validation($data, $files)
{
$errors = parent::validation($data, $files);
if (isset($data['feedbackauthorattachment_filemanager']) and isset($this->workshop->overallfeedbackfiletypes)) {
$whitelist = workshop::normalize_file_extensions($this->workshop->overallfeedbackfiletypes);
if ($whitelist) {
$draftfiles = file_get_drafarea_files($data['feedbackauthorattachment_filemanager']);
if ($draftfiles) {
$wrongfiles = array();
foreach ($draftfiles->list as $file) {
if (!workshop::is_allowed_file_type($file->filename, $whitelist)) {
$wrongfiles[] = $file->filename;
}
}
if ($wrongfiles) {
$a = array('whitelist' => workshop::clean_file_extensions($whitelist), 'wrongfiles' => implode(', ', $wrongfiles));
$errors['feedbackauthorattachment_filemanager'] = get_string('err_wrongfileextension', 'mod_workshop', $a);
}
}
}
}
return $errors;
}