Merge branch 'wip-files23' of git://github.com/marinaglancy/moodle

This commit is contained in:
Dan Poltawski 2012-05-21 18:19:32 +08:00
commit 2b4f1cbc32
582 changed files with 7417 additions and 3334 deletions

View File

@ -1,12 +1,27 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
require_once(dirname(dirname(__FILE__)) . '/config.php');
require_once($CFG->dirroot . '/repository/lib.php');
require_once($CFG->libdir . '/adminlib.php');
$repository = optional_param('repos', '', PARAM_FORMAT);
$action = optional_param('action', '', PARAM_ALPHA);
$repository = optional_param('repos', '', PARAM_ALPHANUMEXT);
$action = optional_param('action', '', PARAM_ACTION);
$sure = optional_param('sure', '', PARAM_ALPHA);
$downloadcontents = optional_param('downloadcontents', '', PARAM_ALPHA);
$display = true; // fall through to normal display
@ -42,6 +57,10 @@ $configstr = get_string('manage', 'repository');
$return = true;
if (!empty($action)) {
require_sesskey();
}
/**
* Helper function that generates a moodle_url object
* relevant to the repository
@ -154,7 +173,7 @@ if (($action == 'edit') || ($action == 'new')) {
if ($action == 'edit') {
$instanceoptionnames = repository::static_function($repository, 'get_instance_option_names');
if (!empty($instanceoptionnames)) {
repository::display_instances_list(get_context_instance(CONTEXT_SYSTEM), $repository);
repository::display_instances_list(context_system::instance(), $repository);
}
}
}
@ -185,7 +204,14 @@ if (($action == 'edit') || ($action == 'new')) {
if (!confirm_sesskey()) {
print_error('confirmsesskeybad', '', $baseurl);
}
if ($repositorytype->delete()) {
if (!empty($downloadcontents) and $downloadcontents == 'yes') {
$downloadcontents = true;
} else {
$downloadcontents = false;
}
if ($repositorytype->delete($downloadcontents)) {
redirect($baseurl);
} else {
print_error('instancenotdeleted', 'repository', $baseurl);
@ -193,7 +219,34 @@ if (($action == 'edit') || ($action == 'new')) {
exit;
} else {
echo $OUTPUT->header();
echo $OUTPUT->confirm(get_string('confirmremove', 'repository', $repositorytype->get_readablename()), $sesskeyurl . '&action=delete&repos=' . $repository . '&sure=yes', $baseurl);
$message = get_string('confirmremove', 'repository', $repositorytype->get_readablename());
$output = $OUTPUT->box_start('generalbox', 'notice');
$output .= html_writer::tag('p', $message);
$removeurl = new moodle_url($sesskeyurl);
$removeurl->params(array(
'action' =>'delete',
'repos' => $repository,
'sure' => 'yes',
));
$removeanddownloadurl = new moodle_url($sesskeyurl);
$removeanddownloadurl->params(array(
'action' =>'delete',
'repos'=> $repository,
'sure' => 'yes',
'downloadcontents' => 'yes',
));
$output .= $OUTPUT->single_button($removeurl, get_string('continueuninstall', 'repository'));
$output .= $OUTPUT->single_button($removeanddownloadurl, get_string('continueuninstallanddownload', 'repository'));
$output .= $OUTPUT->single_button($baseurl, get_string('cancel'));
$output .= $OUTPUT->box_end();
echo $output;
$return = false;
}
} else if ($action == 'moveup') {
@ -255,7 +308,7 @@ if (($action == 'edit') || ($action == 'new')) {
// Calculate number of instances in order to display them for the Moodle administrator
if (!empty($instanceoptionnames)) {
$params = array();
$params['context'] = array(get_system_context());
$params['context'] = array(context_system::instance());
$params['onlyvisible'] = false;
$params['type'] = $typename;
$admininstancenumber = count(repository::static_function($typename, 'get_instances', $params));

View File

@ -1,18 +1,35 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
require_once(dirname(dirname(__FILE__)) . '/config.php');
require_once($CFG->dirroot . '/repository/lib.php');
require_once($CFG->libdir . '/adminlib.php');
require_sesskey();
// id of repository
$edit = optional_param('edit', 0, PARAM_INT);
$new = optional_param('new', '', PARAM_FORMAT);
$new = optional_param('new', '', PARAM_PLUGIN);
$hide = optional_param('hide', 0, PARAM_INT);
$delete = optional_param('delete', 0, PARAM_INT);
$sure = optional_param('sure', '', PARAM_ALPHA);
$type = optional_param('type', '', PARAM_PLUGIN);
$downloadcontents = optional_param('downloadcontents', '', PARAM_ALPHA);
$context = get_context_instance(CONTEXT_SYSTEM);
$context = context_system::instance();
$pagename = 'repositorycontroller';
@ -24,16 +41,20 @@ if ($edit){
$pagename = 'repositoryinstancenew';
}
admin_externalpage_setup($pagename);
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
admin_externalpage_setup($pagename, '', null, new moodle_url('/admin/repositoryinstances.php'));
require_capability('moodle/site:config', $context);
$baseurl = new moodle_url("/$CFG->admin/repositoryinstance.php", array('sesskey'=>sesskey()));
$parenturl = new moodle_url("/$CFG->admin/repository.php", array(
'sesskey'=>sesskey(),
'action'=>'edit',
));
$sesskeyurl = "$CFG->wwwroot/$CFG->admin/repositoryinstance.php?sesskey=" . sesskey();
$baseurl = "$CFG->wwwroot/$CFG->admin/repository.php?session=". sesskey() .'&action=edit&repos=';
if ($new) {
$baseurl .= $new;
}
else {
$baseurl .= $type;
$parenturl->param('repos', $new);
} else {
$parenturl->param('repos', $type);
}
$return = true;
@ -48,7 +69,7 @@ if (!empty($edit) || !empty($new)) {
$typeid = $instance->options['typeid'];
} else {
$plugin = $new;
$typeid = $new;
$typeid = null;
$instance = null;
}
@ -57,12 +78,9 @@ if (!empty($edit) || !empty($new)) {
// end setup, begin output
if ($mform->is_cancelled()){
redirect($baseurl);
redirect($parenturl);
exit;
} else if ($fromform = $mform->get_data()){
if (!confirm_sesskey()) {
print_error('confirmsesskeybad', '', $baseurl);
}
if ($edit) {
$settings = array();
$settings['name'] = $fromform->name;
@ -77,13 +95,13 @@ if (!empty($edit) || !empty($new)) {
}
$success = $instance->set_option($settings);
} else {
$success = repository::static_function($plugin, 'create', $plugin, 0, get_system_context(), $fromform);
$success = repository::static_function($plugin, 'create', $plugin, 0, $context, $fromform);
$data = data_submitted();
}
if ($success) {
redirect($baseurl);
redirect($parenturl);
} else {
print_error('instancenotsaved', 'repository', $baseurl);
print_error('instancenotsaved', 'repository', $parenturl);
}
exit;
} else {
@ -95,9 +113,6 @@ if (!empty($edit) || !empty($new)) {
$return = false;
}
} else if (!empty($hide)) {
if (!confirm_sesskey()) {
print_error('confirmsesskeybad', '', $baseurl);
}
$instance = repository::get_type_by_typename($hide);
$instance->hide();
$return = true;
@ -108,25 +123,43 @@ if (!empty($edit) || !empty($new)) {
throw new repository_exception('readonlyinstance', 'repository');
}
if ($sure) {
if (!confirm_sesskey()) {
print_error('confirmsesskeybad', '', $baseurl);
}
if ($instance->delete()) {
$deletedstr = get_string('instancedeleted', 'repository');
redirect($baseurl, $deletedstr, 3);
if (!empty($downloadcontents) and $downloadcontents == 'yes') {
$downloadcontents = true;
} else {
print_error('instancenotdeleted', 'repository', $baseurl);
$downloadcontents = false;
}
if ($instance->delete($downloadcontents)) {
$deletedstr = get_string('instancedeleted', 'repository');
redirect($parenturl, $deletedstr, 3);
} else {
print_error('instancenotdeleted', 'repository', $parenturl);
}
exit;
}
echo $OUTPUT->header();
echo $OUTPUT->confirm(get_string('confirmdelete', 'repository', $instance->name), "$sesskeyurl&type=$type'&delete=$delete'&sure=yes", "$CFG->wwwroot/$CFG->admin/repositoryinstance.php?session=". sesskey());
echo $OUTPUT->box_start('generalbox', 'notice');
$continueurl = new moodle_url($baseurl, array(
'type' => $type,
'delete' => $delete,
'sure' => 'yes',
));
$continueanddownloadurl = new moodle_url($continueurl, array(
'downloadcontents' => 'yes'
));
$message = get_string('confirmdelete', 'repository', $instance->name);
echo html_writer::tag('p', $message);
echo $OUTPUT->single_button($continueurl, get_string('continueuninstall', 'repository'));
echo $OUTPUT->single_button($continueanddownloadurl, get_string('continueuninstallanddownload', 'repository'));
echo $OUTPUT->single_button($parenturl, get_string('cancel'));
echo $OUTPUT->box_end();
$return = false;
}
if (!empty($return)) {
redirect($baseurl);
redirect($parenturl);
}
echo $OUTPUT->footer();

View File

@ -60,9 +60,8 @@ if (!isset($args[0]) || !in_array($args[0], $alloweddirs)) {
print_error('invalidarguments');
}
// only serve some controlled extensions
$allowedextensions = array('text/html', 'text/css', 'image/gif', 'application/x-javascript');
if (!in_array(mimeinfo('type', $filepath), $allowedextensions)) {
// only serve some controlled extensions/mimetypes
if (!file_extension_in_typegroup($filepath, array('web_file', 'web_image'), true)) {
print_error('invalidarguments');
}

View File

@ -27,7 +27,7 @@ class backup_files_edit_form extends moodleform {
function definition() {
$mform =& $this->_form;
$contextid = $this->_customdata['contextid'];
$options = array('subdirs'=>0, 'maxfiles'=>-1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL);
$options = array('subdirs'=>0, 'maxfiles'=>-1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL | FILE_REFERENCE);
$mform->addElement('filemanager', 'files_filemanager', get_string('files'), null, $options);
$mform->addElement('hidden', 'contextid', $this->_customdata['contextid']);
$mform->addElement('hidden', 'currentcontext', $this->_customdata['currentcontext']);

View File

@ -1404,7 +1404,7 @@ class backup_final_files_structure_step extends backup_structure_step {
'contenthash', 'contextid', 'component', 'filearea', 'itemid',
'filepath', 'filename', 'userid', 'filesize',
'mimetype', 'status', 'timecreated', 'timemodified',
'source', 'author', 'license', 'sortorder'));
'source', 'author', 'license', 'sortorder', 'reference', 'repositoryid'));
// Build the tree
@ -1412,9 +1412,12 @@ class backup_final_files_structure_step extends backup_structure_step {
// Define sources
$file->set_source_sql("SELECT f.*
$file->set_source_sql("SELECT f.*, r.repositoryid, r.reference
FROM {files} f
JOIN {backup_ids_temp} bi ON f.id = bi.itemid
JOIN {files_reference} r
ON r.id = f.referencefileid
JOIN {backup_ids_temp} bi
ON f.id = bi.itemid
WHERE bi.backupid = ?
AND bi.itemname = 'filefinal'", array(backup::VAR_BACKUPID));
@ -1442,6 +1445,8 @@ class backup_main_structure_step extends backup_structure_step {
$info['backup_date'] = time();
$info['backup_uniqueid']= $this->get_backupid();
$info['mnet_remoteusers']=backup_controller_dbops::backup_includes_mnet_remote_users($this->get_backupid());
$info['include_file_references_to_external_content'] =
backup_controller_dbops::backup_includes_file_references($this->get_backupid());
$info['original_wwwroot']=$CFG->wwwroot;
$info['original_site_identifier_hash'] = md5(get_site_identifier());
$info['original_course_id'] = $this->get_courseid();
@ -1461,7 +1466,7 @@ class backup_main_structure_step extends backup_structure_step {
$information = new backup_nested_element('information', null, array(
'name', 'moodle_version', 'moodle_release', 'backup_version',
'backup_release', 'backup_date', 'mnet_remoteusers', 'original_wwwroot',
'backup_release', 'backup_date', 'mnet_remoteusers', 'include_file_references_to_external_content', 'original_wwwroot',
'original_site_identifier_hash', 'original_course_id',
'original_course_fullname', 'original_course_shortname', 'original_course_startdate',
'original_course_contextid', 'original_system_contextid'));
@ -1584,8 +1589,12 @@ class backup_store_backup_file extends backup_execution_step {
// Calculate the zip fullpath (in OS temp area it's always backup.mbz)
$zipfile = $basepath . '/backup.mbz';
$has_file_references = backup_controller_dbops::backup_includes_file_references($this->get_backupid());
// Perform storage and return it (TODO: shouldn't be array but proper result object)
return array('backup_destination' => backup_helper::store_backup_file($this->get_backupid(), $zipfile));
return array(
'backup_destination' => backup_helper::store_backup_file($this->get_backupid(), $zipfile),
'include_file_references_to_external_content' => $has_file_references
);
}
}

View File

@ -586,11 +586,23 @@ class restore_load_included_files extends restore_structure_step {
return array($file);
}
// Processing functions go here
/**
* Processing functions go here
*
* @param array $data one file record including repositoryid and reference
*/
public function process_file($data) {
$data = (object)$data; // handy
$isreference = !empty($data->repositoryid);
$issamesite = $this->task->is_samesite();
// If it's not samesite, we skip file refernces
if (!$issamesite && $isreference) {
return;
}
// load it if needed:
// - it it is one of the annotated inforef files (course/section/activity/block)
// - it is one "user", "group", "grouping", "grade", "question" or "qtype_xxxx" component file (that aren't sent to inforef ever)
@ -601,6 +613,7 @@ class restore_load_included_files extends restore_structure_step {
$data->component == 'grouping' || $data->component == 'grade' ||
$data->component == 'question' || substr($data->component, 0, 5) == 'qtype');
if ($isfileref || $iscomponent) {
// Process files
restore_dbops::set_backup_files_record($this->get_restoreid(), $data);
}
}

View File

@ -409,6 +409,27 @@ abstract class backup_controller_dbops extends backup_dbops {
return (int)(bool)$count;
}
/**
* Given the backupid, detect if the backup contains references to external contents
*
* @copyright 2012 Dongsheng Cai {@link http://dongsheng.org}
* @return int
*/
public static function backup_includes_file_references($backupid) {
global $CFG, $DB;
$sql = "SELECT count(r.repositoryid)
FROM {files} f
JOIN {files_reference} r
ON r.id = f.referencefileid
JOIN {backup_ids_temp} bi
ON f.id = bi.itemid
WHERE bi.backupid = ?
AND bi.itemname = 'filefinal'";
$count = $DB->count_records_sql($sql, array($backupid));
return (int)(bool)$count;
}
/**
* Given the courseid, return some course related information we want to transport
*

View File

@ -685,6 +685,9 @@ abstract class restore_dbops {
$rs = $DB->get_recordset_sql($sql, $params);
foreach ($rs as $rec) {
$file = (object)unserialize(base64_decode($rec->info));
$isreference = !empty($file->repositoryid);
// ignore root dirs (they are created automatically)
if ($file->filepath == '/' && $file->filename == '.') {
continue;
@ -697,10 +700,12 @@ abstract class restore_dbops {
$fs->create_directory($newcontextid, $component, $filearea, $rec->newitemid, $file->filepath, $file->userid);
continue;
}
// arrived here, file found
// Find file in backup pool
$backuppath = $basepath . backup_file_manager::get_backup_content_file_location($file->contenthash);
if (!file_exists($backuppath)) {
if (!file_exists($backuppath) && !$isreference) {
throw new restore_dbops_exception('file_not_found_in_pool', $file);
}
if (!$fs->file_exists($newcontextid, $component, $filearea, $rec->newitemid, $file->filepath, $file->filename)) {
@ -717,9 +722,13 @@ abstract class restore_dbops {
'author' => $file->author,
'license' => $file->license,
'sortorder' => $file->sortorder);
if ($isreference) {
$fs->create_file_from_reference($file_record, $file->repositoryid, $file->reference);
} else {
$fs->create_file_from_pathname($file_record, $backuppath);
}
}
}
$rs->close();
}
@ -1204,6 +1213,7 @@ abstract class restore_dbops {
public static function set_backup_files_record($restoreid, $filerec) {
global $DB;
// Store external files info in `info` field
$filerec->info = base64_encode(serialize($filerec)); // Serialize the whole rec in info
$filerec->backupid = $restoreid;
$DB->insert_record('backup_files_temp', $filerec);

View File

@ -73,6 +73,10 @@ class backup_file_manager {
$fs = get_file_storage();
$file = $fs->get_file_instance($filerecorid);
// If the file is external file, skip copying.
if ($file->is_external_file()) {
return;
}
// Calculate source and target paths (use same subdirs strategy for both)
$targetfilepath = self::get_backup_storage_base_dir($backupid) . '/' .

View File

@ -145,6 +145,7 @@ abstract class backup_general_helper extends backup_helper {
$info->original_course_startdate= $infoarr['original_course_startdate'];
$info->original_course_contextid= $infoarr['original_course_contextid'];
$info->original_system_contextid= $infoarr['original_system_contextid'];
$info->include_file_references_to_external_content = $infoarr['include_file_references_to_external_content'];
$info->type = $infoarr['details']['detail'][0]['type'];
$info->format = $infoarr['details']['detail'][0]['format'];
$info->mode = $infoarr['details']['detail'][0]['mode'];

View File

@ -470,6 +470,9 @@ class backup_ui_stage_complete extends backup_ui_stage_final {
$output = '';
$output .= $renderer->box_start();
if (!empty($this->results['include_file_references_to_external_content'])) {
$output .= $renderer->notification(get_string('filereferencesincluded', 'backup'), 'notifyproblem');
}
$output .= $renderer->notification(get_string('executionsuccess', 'backup'), 'notifysuccess');
$output .= $renderer->continue_button($restorerul);
$output .= $renderer->box_end();

View File

@ -92,6 +92,16 @@ class core_backup_renderer extends plugin_renderer_base {
$html .= $this->backup_detail_pair(get_string('originalwwwroot', 'backup'),
html_writer::tag('span', $details->original_wwwroot, array('class'=>'originalwwwroot')).
html_writer::tag('span', '['.$details->original_site_identifier_hash.']', array('class'=>'sitehash sub-detail')));
if (!empty($details->include_file_references_to_external_content)) {
$message = '';
if (backup_general_helper::backup_is_samesite($details)) {
$message = $yestick . ' ' . get_string('filereferencessamesite', 'backup');
} else {
$message = $notick . ' ' . get_string('filereferencesnotsamesite', 'backup');
}
$html .= $this->backup_detail_pair(get_string('includefilereferences', 'backup'), $message);
}
$html .= html_writer::end_tag('div');
$html .= html_writer::start_tag('div', array('class'=>'backup-section settings-section'));

View File

@ -1,5 +1,8 @@
<?php
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/filelib.php');
class block_activity_modules extends block_list {
function init() {
$this->title = get_string('pluginname', 'block_activity_modules');
@ -50,7 +53,7 @@ class block_activity_modules extends block_list {
foreach ($modfullnames as $modname => $modfullname) {
if ($modname === 'resources') {
$icon = '<img src="'.$OUTPUT->pix_url('f/html') . '" class="icon" alt="" />&nbsp;';
$icon = $OUTPUT->pix_icon(file_extension_icon('.htm'), '', 'moodle', array('class' => 'icon')). '&nbsp;';
$this->content->items[] = '<a href="'.$CFG->wwwroot.'/course/resources.php?id='.$course->id.'">'.$icon.$modfullname.'</a>';
} else {
$icon = '<img src="'.$OUTPUT->pix_url('icon', $modname) . '" class="icon" alt="" />&nbsp;';

View File

@ -45,7 +45,7 @@ $PAGE->set_pagelayout('mydashboard');
$PAGE->set_pagetype('user-private-files');
$data = new stdClass();
$options = array('subdirs'=>1, 'maxbytes'=>$CFG->userquota, 'maxfiles'=>-1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL);
$options = array('subdirs'=>1, 'maxbytes'=>$CFG->userquota, 'maxfiles'=>-1, 'accepted_types'=>'*');
file_prepare_standard_filemanager($data, 'files', $options, $context, 'user', 'private', 0);
$mform = new block_private_files_form(null, array('data'=>$data, 'options'=>$options));

View File

@ -65,14 +65,13 @@ class block_private_files_renderer extends plugin_renderer_base {
}
$result = '<ul>';
foreach ($dir['subdirs'] as $subdir) {
$image = $this->output->pix_icon("f/folder", $subdir['dirname'], 'moodle', array('class'=>'icon'));
$image = $this->output->pix_icon(file_folder_icon(), $subdir['dirname'], 'moodle', array('class'=>'icon'));
$result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.s($subdir['dirname']).'</div> '.$this->htmllize_tree($tree, $subdir).'</li>';
}
foreach ($dir['files'] as $file) {
$url = file_encode_url("$CFG->wwwroot/pluginfile.php", '/'.$tree->context->id.'/user/private'.$file->get_filepath().$file->get_filename(), true);
$filename = $file->get_filename();
$icon = mimeinfo("icon", $filename);
$image = $this->output->pix_icon("f/$icon", $filename, 'moodle', array('class'=>'icon'));
$image = $this->output->pix_icon(file_file_icon($file), $filename, 'moodle', array('class'=>'icon'));
$result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.html_writer::link($url, $image.'&nbsp;'.$filename).'</div></li>';
}
$result .= '</ul>';

View File

@ -513,10 +513,7 @@ class blog_entry {
$ffurl = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.SYSCONTEXTID.'/blog/attachment/'.$this->id.'/'.$filename);
$mimetype = $file->get_mimetype();
$icon = mimeinfo_from_type("icon", $mimetype);
$type = mimeinfo_from_type("type", $mimetype);
$image = $OUTPUT->pix_icon("f/$icon", $filename, 'moodle', array('class'=>'icon'));
$image = $OUTPUT->pix_icon(file_file_icon($file), $filename, 'moodle', array('class'=>'icon'));
if ($return == "html") {
$output .= html_writer::link($ffurl, $image);
@ -526,7 +523,7 @@ class blog_entry {
$output .= "$strattachment $filename:\n$ffurl\n";
} else {
if (in_array($type, array('image/gif', 'image/jpeg', 'image/png'))) { // Image attachments don't get printed as links
if (file_mimetype_in_typegroup($file->get_mimetype(), 'web_image')) { // Image attachments don't get printed as links
$imagereturn .= '<br /><img src="'.$ffurl.'" alt="" />';
} else {
$imagereturn .= html_writer::link($ffurl, $image);

View File

@ -1518,13 +1518,6 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false,
//Accessibility: for files get description via icon, this is very ugly hack!
$altname = '';
$altname = $mod->modfullname;
if (!empty($customicon)) {
$archetype = plugin_supports('mod', $mod->modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER);
if ($archetype == MOD_ARCHETYPE_RESOURCE) {
$mimetype = mimeinfo_from_icon('type', $customicon);
$altname = get_mimetype_description($mimetype);
}
}
// Avoid unnecessary duplication: if e.g. a forum name already
// includes the word forum (or Forum, etc) then it is unhelpful
// to include that in the accessible description that is added.

View File

@ -36,6 +36,7 @@ if (isguestuser()) {
}
$relativepath = get_file_argument();
$preview = optional_param('preview', null, PARAM_ALPHANUM);
// relative path must start with '/'
if (!$relativepath) {
@ -84,4 +85,4 @@ if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->get_filename() ==
// finally send the file
// ========================================
session_get_instance()->write_close(); // unlock session during fileserving
send_stored_file($file, 0, false, true); // force download - security first!
send_stored_file($file, 0, false, true, array('preview' => $preview)); // force download - security first!

View File

@ -21,7 +21,7 @@ class coursefiles_edit_form extends moodleform {
function definition() {
$mform =& $this->_form;
$contextid = $this->_customdata['contextid'];
$options = array('subdirs'=>1, 'maxfiles'=>-1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL);
$options = array('subdirs'=>1, 'maxfiles'=>-1, 'accepted_types'=>'*');
$mform->addElement('filemanager', 'files_filemanager', '', null, $options);
$mform->addElement('hidden', 'contextid', $this->_customdata['contextid']);
$this->set_data($this->_customdata['data']);

View File

@ -70,10 +70,10 @@ switch ($action) {
if ($child->is_directory()) {
$fileitem['isdir'] = true;
$fileitem['url'] = $url->out(false);
$fileitem['icon'] = $OUTPUT->pix_icon('f/folder', get_string('icon'));
$fileitem['icon'] = $OUTPUT->pix_icon(file_folder_icon(), get_string('icon'));
} else {
$fileitem['url'] = $child->get_url();
$fileitem['icon'] = $OUTPUT->pix_icon('f/'.mimeinfo('icon', $child->get_visible_name()), get_string('icon'));
$fileitem['icon'] = $OUTPUT->pix_icon(file_file_icon($child), get_string('icon'));
}
$tree[] = $fileitem;
}

View File

@ -56,25 +56,31 @@ class core_files_renderer extends plugin_renderer_base {
$html .= $this->output->box_start();
$table = new html_table();
$table->head = array(get_string('filename', 'backup'), get_string('size'), get_string('modified'));
$table->align = array('left', 'right', 'right');
$table->head = array(get_string('name'), get_string('lastmodified'), get_string('size', 'repository'), get_string('type', 'repository'));
$table->align = array('left', 'left', 'left', 'left');
$table->width = '100%';
$table->data = array();
foreach ($tree->tree as $file) {
if (!empty($file['isdir'])) {
$table->data[] = array(
html_writer::link($file['url'], $this->output->pix_icon('f/folder', 'icon') . ' ' . $file['filename']),
'',
$file['filedate'],
);
} else {
$table->data[] = array(
html_writer::link($file['url'], $this->output->pix_icon('f/'.mimeinfo('icon', $file['filename']), get_string('icon')) . ' ' . $file['filename']),
$file['filesize'],
$file['filedate'],
);
$filedate = $filesize = $filetype = '';
if ($file['filedate']) {
$filedate = userdate($file['filedate'], get_string('strftimedatetimeshort', 'langconfig'));
}
if (empty($file['isdir'])) {
if ($file['filesize']) {
$filesize = display_size($file['filesize']);
}
$fileicon = file_file_icon($file, 24);
$filetype = get_mimetype_description($file);
} else {
$fileicon = file_folder_icon(24);
}
$table->data[] = array(
html_writer::link($file['url'], $this->output->pix_icon($fileicon, get_string('icon')) . ' ' . $file['filename']),
$filedate,
$filesize,
$filetype
);
}
$html .= html_writer::table($table);
@ -82,8 +88,812 @@ class core_files_renderer extends plugin_renderer_base {
$html .= $this->output->box_end();
return $html;
}
/**
* Prints the file manager and initializes all necessary libraries
*
* <pre>
* $fm = new form_filemanager($options);
* $output = get_renderer('core', 'files');
* echo $output->render($fm);
* </pre>
*
* @param form_filemanager $fm File manager to render
* @return string HTML fragment
*/
public function render_form_filemanager($fm) {
static $filemanagertemplateloaded;
$html = $this->fm_print_generallayout($fm);
$module = array(
'name'=>'form_filemanager',
'fullpath'=>'/lib/form/filemanager.js',
'requires' => array('core_filepicker', 'base', 'io-base', 'node', 'json', 'core_dndupload', 'panel', 'resize-plugin', 'dd-plugin'),
'strings' => array(
array('error', 'moodle'), array('info', 'moodle'), array('confirmdeletefile', 'repository'),
array('draftareanofiles', 'repository'), array('entername', 'repository'), array('enternewname', 'repository'),
array('invalidjson', 'repository'), array('popupblockeddownload', 'repository'),
array('unknownoriginal', 'repository'), array('confirmdeletefolder', 'repository'),
array('confirmdeletefilewithhref', 'repository'), array('confirmrenamefolder', 'repository'),
array('confirmrenamefile', 'repository')
)
);
if (empty($filemanagertemplateloaded)) {
$filemanagertemplateloaded = true;
$this->page->requires->js_init_call('M.form_filemanager.set_templates',
array($this->filemanager_js_templates()), true, $module);
}
$this->page->requires->js_init_call('M.form_filemanager.init', array($fm->options), true, $module);
// non javascript file manager
$html .= '<noscript>';
$html .= "<div><object type='text/html' data='".$fm->get_nonjsurl()."' height='160' width='600' style='border:1px solid #000'></object></div>";
$html .= '</noscript>';
return $html;
}
/**
* Returns html for displaying one file manager
*
* The main element in HTML must have id="filemanager-{$client_id}" and
* class="filemanager fm-loading";
* After all necessary code on the page (both html and javascript) is loaded,
* the class fm-loading will be removed and added class fm-loaded;
* The main element (class=filemanager) will be assigned the following classes:
* 'fm-maxfiles' - when filemanager has maximum allowed number of files;
* 'fm-nofiles' - when filemanager has no files at all (although there might be folders);
* 'fm-noitems' - when current view (folder) has no items - neither files nor folders;
* 'fm-updating' - when current view is being updated (usually means that loading icon is to be displayed);
* 'fm-nomkdir' - when 'Make folder' action is unavailable (empty($fm->options->subdirs) == true)
*
* Element with class 'filemanager-container' will be holding evens for dnd upload (dragover, etc.).
* It will have class:
* 'dndupload-ready' - when a file is being dragged over the browser
* 'dndupload-over' - when file is being dragged over this filepicker (additional to 'dndupload-ready')
* 'dndupload-uploading' - during the upload process (note that after dnd upload process is
* over, the file manager will refresh the files list and therefore will have for a while class
* fm-updating. Both waiting processes should look similar so the images don't jump for user)
*
* If browser supports Drag-and-drop, the body element will have class 'dndsupported',
* otherwise - 'dndnotsupported';
*
* Element with class 'fp-content' will be populated with files list;
* Element with class 'fp-btn-add' will hold onclick event for adding a file (opening filepicker);
* Element with class 'fp-btn-mkdir' will hold onclick event for adding new folder;
* Element with class 'fp-btn-download' will hold onclick event for download action;
*
* Element with class 'fp-path-folder' is a template for one folder in path toolbar.
* It will hold mouse click event and will be assigned classes first/last/even/odd respectfully.
* Parent element will receive class 'empty' when there are no folders to be displayed;
* The content of subelement with class 'fp-path-folder-name' will be substituted with folder name;
*
* Element with class 'fp-viewbar' will have the class 'enabled' or 'disabled' when view mode
* can be changed or not;
* Inside element with class 'fp-viewbar' there are expected elements with classes
* 'fp-vb-icons', 'fp-vb-tree' and 'fp-vb-details'. They will handle onclick events to switch
* between the view modes, the last clicked element will have the class 'checked';
*
* @param form_filemanager $fm
* @return string
*/
private function fm_print_generallayout($fm) {
global $OUTPUT;
$options = $fm->options;
$client_id = $options->client_id;
$straddfile = get_string('addfile', 'repository');
$strmakedir = get_string('makeafolder', 'moodle');
$strdownload = get_string('downloadfolder', 'repository');
$strloading = get_string('loading', 'repository');
$strnofilesattached = get_string('nofilesattached', 'repository');
$strdroptoupload = get_string('droptoupload', 'moodle');
$icon_progress = $OUTPUT->pix_icon('i/loading_small', $strloading).'';
$restrictions = $this->fm_print_restrictions($fm);
$strdndenabled = get_string('dndenabled_insentence', 'moodle').$OUTPUT->help_icon('dndenabled');
$strdndenabledinbox = get_string('dndenabled_inbox', 'moodle');
$loading = get_string('loading', 'repository');
$html = '
<div id="filemanager-'.$client_id.'" class="filemanager fm-loading">
<div class="fp-restrictions">
'.$restrictions.'
<span class="dndupload-message"> - '.$strdndenabled.' </span>
</div>
<div class="fp-navbar">
<div class="filemanager-toolbar">
<div class="fp-toolbar">
<div class="{!}fp-btn-add"><a href="#"><img src="'.$this->pix_url('a/add_file').'" /> '.$straddfile.'</a></div>
<div class="{!}fp-btn-mkdir"><a href="#"><img src="'.$this->pix_url('a/create_folder').'" /> '.$strmakedir.'</a></div>
<div class="{!}fp-btn-download"><a href="#"><img src="'.$this->pix_url('a/download_all').'" /> '.$strdownload.'</a></div>
</div>
<div class="{!}fp-viewbar">
<a class="{!}fp-vb-icons" href="#"></a>
<a class="{!}fp-vb-details" href="#"></a>
<a class="{!}fp-vb-tree" href="#"></a>
</div>
</div>
<div class="fp-pathbar">
<span class="{!}fp-path-folder"><a class="{!}fp-path-folder-name" href="#"></a></span>
</div>
</div>
<div class="filemanager-loading mdl-align">'.$icon_progress.'</div>
<div class="filemanager-container" >
<div class="fm-content-wrapper">
<div class="fp-content"></div>
<div class="fm-empty-container <!--mdl-align-->">'.$strnofilesattached.'
<span class="dndupload-message">'.$strdndenabledinbox.'<br/><span class="dndupload-arrow"></span></span>
</div>
<div class="dndupload-target">'.$strdroptoupload.'<br/><span class="dndupload-arrow"></span></div>
<div class="dndupload-uploadinprogress">'.$icon_progress.'</div>
</div>
<div class="filemanager-updating">'.$icon_progress.'</div>
</div>
</div>';
return preg_replace('/\{\!\}/', '', $html);
}
/**
* FileManager JS template for displaying one file in 'icon view' mode.
*
* Except for elements described in fp_js_template_iconfilename, this template may also
* contain element with class 'fp-contextmenu'. If context menu is available for this
* file, the top element will receive the additional class 'fp-hascontextmenu' and
* the element with class 'fp-contextmenu' will hold onclick event for displaying
* the context menu.
*
* @see fp_js_template_iconfilename()
* @return string
*/
private function fm_js_template_iconfilename() {
$rv = '
<div class="fp-file">
<a href="#">
<div style="position:relative;">
<div class="{!}fp-thumbnail"></div>
<div class="fp-reficons1"></div>
<div class="fp-reficons2"></div>
</div>
<div class="fp-filename-field">
<div class="{!}fp-filename"></div>
</div>
</a>
<a class="{!}fp-contextmenu" href="#">'.$this->pix_icon('i/menu', '').'</a>
</div>';
return preg_replace('/\{\!\}/', '', $rv);
}
/**
* FileManager JS template for displaying file name in 'table view' and 'tree view' modes.
*
* Except for elements described in fp_js_template_listfilename, this template may also
* contain element with class 'fp-contextmenu'. If context menu is available for this
* file, the top element will receive the additional class 'fp-hascontextmenu' and
* the element with class 'fp-contextmenu' will hold onclick event for displaying
* the context menu.
*
* @todo MDL-32736 remove onclick="return false;"
* @see fp_js_template_listfilename()
* @return string
*/
private function fm_js_template_listfilename() {
$rv = '
<span>
<a href="#">
<span class="{!}fp-icon"></span>
<span class="{!}fp-filename"></span>
</a>
<a class="{!}fp-contextmenu" href="#" onclick="return false;">'.$this->pix_icon('i/menu', '').'</a>
</span>';
return preg_replace('/\{\!\}/', '', $rv);
}
/**
* FileManager JS template for displaying 'Make new folder' dialog.
*
* Must be wrapped in an element, CSS for this element must define width and height of the window;
*
* Must have one input element with type="text" (for users to enter the new folder name);
*
* content of element with class 'fp-dlg-curpath' will be replaced with current path where
* new folder is about to be created;
* elements with classes 'fp-dlg-butcreate' and 'fp-dlg-butcancel' will hold onclick events;
*
* @return string
*/
private function fm_js_template_mkdir() {
$rv = '
<div class="fp-mkdir-dlg">
<p>New folder name:</p>
<input type="text"><br/>
<a class="{!}fp-dlg-butcreate fp-panel-button" href="#">'.get_string('create').'</a>
<a class="{!}fp-dlg-butcancel fp-panel-button" href="#">'.get_string('cancel').'</a>
</div>';
return preg_replace('/\{\!\}/', '', $rv);
}
/**
* FileManager JS template for error/info message displayed as a separate popup window.
*
* @see fp_js_template_message()
* @return string
*/
private function fm_js_template_message() {
return $this->fp_js_template_message();
}
/**
* FileManager JS template for window with file information/actions.
*
* All content must be enclosed in one element, CSS for this class must define width and
* height of the window;
*
* Thumbnail image will be added as content to the element with class 'fp-thumbnail';
*
* Inside the window the elements with the following classnames must be present:
* 'fp-saveas', 'fp-author', 'fp-license', 'fp-path'. Inside each of them must be
* one input element (or select in case of fp-license and fp-path). They may also have labels.
* The elements will be assign with class 'uneditable' and input/select element will become
* disabled if they are not applicable for the particular file;
*
* There may be present elements with classes 'fp-original', 'fp-datemodified', 'fp-datecreated',
* 'fp-size', 'fp-dimensions', 'fp-reflist'. They will receive additional class 'fp-unknown' if
* information is unavailable. If there is information available, the content of embedded
* element with class 'fp-value' will be substituted with the value;
*
* The value of Original ('fp-original') is loaded in separate request. When it is applicable
* but not yet loaded the 'fp-original' element receives additional class 'fp-loading';
*
* The value of 'Aliases/Shortcuts' ('fp-reflist') is also loaded in separate request. When it
* is applicable but not yet loaded the 'fp-original' element receives additional class
* 'fp-loading'. The string explaining that XX references exist will replace content of element
* 'fp-refcount'. Inside '.fp-reflist .fp-value' each reference will be enclosed in <li>;
*
* Elements with classes 'fp-file-update', 'fp-file-download', 'fp-file-delete', 'fp-file-zip',
* 'fp-file-unzip', 'fp-file-setmain' and 'fp-file-cancel' will hold corresponding onclick
* events (there may be several elements with class 'fp-file-cancel');
*
* When confirm button is pressed and file is being selected, the top element receives
* additional class 'loading'. It is removed when response from server is received.
*
* When any of the input fields is changed, the top element receives class 'fp-changed';
* When current file can be set as main - top element receives class 'fp-cansetmain';
* When current file is folder/zip/file - top element receives respectfully class
* 'fp-folder'/'fp-zip'/'fp-file';
*
* @return string
*/
private function fm_js_template_fileselectlayout() {
$strloading = get_string('loading', 'repository');
$icon_progress = $this->pix_icon('i/loading_small', $strloading).'';
$rv = '
<div class="filemanager fp-select">
<div class="fp-select-loading">
<img src="'.$this->pix_url('i/loading').'" />
<p>'.get_string('loading', 'repository').'</p>
</div>
<form>
<div><a class="{!}fp-file-download fp-panel-button" href="#">'.get_string('download').'</a>
<a class="{!}fp-file-delete fp-panel-button" href="#">'.get_string('delete').'</a>
<a class="{!}fp-file-setmain fp-panel-button" href="#">'.get_string('setmainfile', 'repository').'</a>
<a class="{!}fp-file-zip fp-panel-button" href="#">'.get_string('zip', 'editor').'</a>
<a class="{!}fp-file-unzip fp-panel-button" href="#">'.get_string('unzip').'</a>
</div>
<div class="fp-hr"></div>
<table>
<tr class="{!}fp-saveas"><td class="mdl-right"><label>'.get_string('name', 'moodle').'</label>:</td>
<td class="mdl-left"><input type="text"/></td></tr>
<tr class="{!}fp-author"><td class="mdl-right"><label>'.get_string('author', 'repository').'</label>:</td>
<td class="mdl-left"><input type="text" /></td></tr>
<tr class="{!}fp-license"><td class="mdl-right"><label>'.get_string('chooselicense', 'repository').'</label>:</td>
<td class="mdl-left"><select></select></td></tr>
<tr class="{!}fp-path"><td class="mdl-right"><label>'.get_string('path', 'moodle').'</label>:</td>
<td class="mdl-left"><select></select></td></tr>
<tr class="{!}fp-original"><td class="mdl-right"><label>'.get_string('original', 'repository').'</label>:</td>
<td class="mdl-left"><span class="fp-originloading">'.$icon_progress.' '.$strloading.'</span><span class="fp-value"/></td></tr>
<tr class="{!}fp-reflist"><td class="mdl-right"><label>'.get_string('referenceslist', 'repository').'</label>:</td>
<td class="mdl-left"><p class="{!}fp-refcount"/><span class="fp-reflistloading">'.$icon_progress.' '.$strloading.'</span><ul class="fp-value"/></td></tr>
</table>
</form>
<p class="{!}fp-thumbnail"></p>
<form>
<p class="fp-select-update">
<a class="{!}fp-file-update" href="#"><span>'.get_string('update', 'moodle').'</span></a>
<a class="{!}fp-file-cancel" href="#"><span>'.get_string('cancel').'</span></a>
</p>
</form>
<div class="fp-fileinfo">
<div class="{!}fp-datemodified">'.get_string('lastmodified', 'moodle').': <span class="fp-value"/></div>
<div class="{!}fp-datecreated">'.get_string('datecreated', 'repository').': <span class="fp-value"/></div>
<div class="{!}fp-size">'.get_string('size', 'repository').': <span class="fp-value"/></div>
<div class="{!}fp-dimensions">'.get_string('dimensions', 'repository').': <span class="fp-value"/></div>
</div>
</div>';
return preg_replace('/\{\!\}/', '', $rv);
}
/**
* FileManager JS template for popup confirm dialogue window.
*
* Must have one top element, CSS for this element must define width and height of the window;
*
* content of element with class 'fp-dlg-text' will be replaced with dialog text;
* elements with classes 'fp-dlg-butconfirm' and 'fp-dlg-butcancel' will
* hold onclick events;
*
* @return string
*/
private function fm_js_template_confirmdialog() {
$rv = '
<div class="filemanager fp-dlg">
<div class="{!}fp-dlg-text"></div>
<a class="{!}fp-dlg-butconfirm fp-panel-button" href="#">'.get_string('ok').'</a>
<a class="{!}fp-dlg-butcancel fp-panel-button" href="#">'.get_string('cancel').'</a>
</div>';
return preg_replace('/\{\!\}/', '', $rv);
}
/**
* Returns all FileManager JavaScript templates as an array.
*
* @return array
*/
public function filemanager_js_templates() {
$class_methods = get_class_methods($this);
$templates = array();
foreach ($class_methods as $method_name) {
if (preg_match('/^fm_js_template_(.*)$/', $method_name, $matches))
$templates[$matches[1]] = $this->$method_name();
}
return $templates;
}
/**
* Displays restrictions for the file manager
*
* @param form_filemanager $fm
* @return string
*/
private function fm_print_restrictions($fm) {
$maxbytes = display_size($fm->options->maxbytes);
if (empty($options->maxfiles) || $options->maxfiles == -1) {
$maxsize = get_string('maxfilesize', 'moodle', $maxbytes);
//$string['maxfilesize'] = 'Maximum size for new files: {$a}';
} else {
$strparam = (object)array('size' => $maxbytes, 'attachments' => $options->maxfiles);
$maxsize = get_string('maxsizeandattachments', 'moodle', $strparam);
//$string['maxsizeandattachments'] = 'Maximum size for new files: {$a->size}, maximum attachments: {$a->attachments}';
}
// TODO MDL-32020 also should say about 'File types accepted'
return '<span>'. $maxsize. '</span>';
}
/**
* Template for FilePicker with general layout (not QuickUpload).
*
* Must have one top element containing everything else (recommended <div class="file-picker">),
* CSS for this element must define width and height of the filepicker window. Or CSS must
* define min-width, max-width, min-height and max-height and in this case the filepicker
* window will be resizeable;
*
* Element with class 'fp-viewbar' will have the class 'enabled' or 'disabled' when view mode
* can be changed or not;
* Inside element with class 'fp-viewbar' there are expected elements with classes
* 'fp-vb-icons', 'fp-vb-tree' and 'fp-vb-details'. They will handle onclick events to switch
* between the view modes, the last clicked element will have the class 'checked';
*
* Element with class 'fp-repo' is a template for displaying one repository. Other repositories
* will be attached as siblings (classes first/last/even/odd will be added respectfully).
* The currently selected repostory will have class 'active'. Contents of element with class
* 'fp-repo-name' will be replaced with repository name, source of image with class
* 'fp-repo-icon' will be replaced with repository icon;
*
* Element with class 'fp-content' is obligatory and will hold the current contents;
*
* Element with class 'fp-paging' will contain page navigation (will be deprecated soon);
*
* Element with class 'fp-path-folder' is a template for one folder in path toolbar.
* It will hold mouse click event and will be assigned classes first/last/even/odd respectfully.
* Parent element will receive class 'empty' when there are no folders to be displayed;
* The content of subelement with class 'fp-path-folder-name' will be substituted with folder name;
*
* Element with class 'fp-toolbar' will have class 'empty' if all 'Back', 'Search', 'Refresh',
* 'Logout', 'Manage' and 'Help' are unavailable for this repo;
*
* Inside fp-toolbar there are expected elements with classes fp-tb-back, fp-tb-search,
* fp-tb-refresh, fp-tb-logout, fp-tb-manage and fp-tb-help. Each of them will have
* class 'enabled' or 'disabled' if particular repository has this functionality.
* Element with class 'fp-tb-search' must contain empty form inside, it's contents will
* be substituted with the search form returned by repository (in the most cases it
* is generated with template core_repository_renderer::repository_default_searchform);
* Other elements must have either <a> or <button> element inside, it will hold onclick
* event for corresponding action; labels for fp-tb-back and fp-tb-logout may be
* replaced with those specified by repository;
*
* @return string
*/
private function fp_js_template_generallayout() {
$rv = '
<div class="file-picker fp-generallayout">
<div class="fp-repo-area">
<ul class="fp-list">
<li class="{!}fp-repo"><a href="#"><img class="{!}fp-repo-icon" width="16" height="16" />&nbsp;<span class="{!}fp-repo-name" /span></a></li>
</ul>
</div>
<div class="fp-repo-items">
<div class="fp-navbar">
<div>
<div class="{!}fp-toolbar">
<div class="{!}fp-tb-back"><a href="#">'.get_string('back', 'repository').'</a></div>
<div class="{!}fp-tb-search fp-search"><form/></div>
<div class="{!}fp-tb-refresh"><a href="#"><img src="'.$this->pix_url('a/refresh').'" /></a></div>
<div class="{!}fp-tb-logout"><img src="'.$this->pix_url('a/logout').'" /><a href="#"></a></div>
<div class="{!}fp-tb-manage"><a href="#"><img src="'.$this->pix_url('a/setting').'" /> '.get_string('manageurl', 'repository').'</a></div>
<div class="{!}fp-tb-help"><a href="#"><img src="'.$this->pix_url('a/help').'" /> '.get_string('help').'</a></div>
</div>
<div class="{!}fp-viewbar">
<a class="{!}fp-vb-icons" href="#"></a>
<a class="{!}fp-vb-details" href="#"></a>
<a class="{!}fp-vb-tree" href="#"></a>
</div>
</div>
<div class="fp-pathbar">
<span class="{!}fp-path-folder"><a class="{!}fp-path-folder-name" href="#"></a></span>
</div>
</div>
<div class="{!}fp-content"></div>
</div>
</div>';
return preg_replace('/\{\!\}/', '', $rv);
}
/**
* FilePicker JS template for displaying one file in 'icon view' mode.
*
* the element with class 'fp-thumbnail' will be resized to the repository thumbnail size
* (both width and height, unless min-width and/or min-height is set in CSS) and the content of
* an element will be replaced with an appropriate img;
*
* the width of element with class 'fp-filename' will be set to the repository thumbnail width
* (unless min-width is set in css) and the content of an element will be replaced with filename
* supplied by repository;
*
* top element(s) will have class fp-folder if the element is a folder;
*
* List of files will have parent <div> element with class 'fp-iconview'
*
* @return string
*/
private function fp_js_template_iconfilename() {
$rv = '
<a class="fp-file" href="#" >
<div class="{!}fp-thumbnail"></div>
<div class="fp-filename-field">
<p class="{!}fp-filename"></p>
</div>
</a>';
return preg_replace('/\{\!\}/', '', $rv);
}
/**
* FilePicker JS template for displaying file name in 'table view' and 'tree view' modes.
*
* content of the element with class 'fp-icon' will be replaced with an appropriate img;
*
* content of element with class 'fp-filename' will be replaced with filename supplied by
* repository;
*
* top element(s) will have class fp-folder if the element is a folder;
*
* Note that tree view and table view are the YUI widgets and therefore there are no
* other templates. The widgets will be wrapped in <div> with class fp-treeview or
* fp-tableview (respectfully).
*
* @return string
*/
private function fp_js_template_listfilename() {
$rv = '<span><span class="{!}fp-icon"></span> <span class="{!}fp-filename"></span></span>';
return preg_replace('/\{\!\}/', '', $rv);
}
/**
* FilePicker JS template for displaying link/loading progress for fetching of the next page
*
* This text is added to .fp-content AFTER .fp-iconview/.fp-treeview/.fp-tableview
*
* Must have one parent element with class 'fp-nextpage'. It will be assigned additional
* class 'loading' during loading of the next page (it is recommended that in this case the link
* becomes unavailable). Also must contain one element <a> or <button> that will hold
* onclick event for displaying of the next page. The event will be triggered automatically
* when user scrolls to this link.
*
* @return string
*/
private function fp_js_template_nextpage() {
$rv = '
<div class="{!}fp-nextpage">
<div class="fp-nextpage-link"><a href="#">'.get_string('more').'</a></div>
<div class="fp-nextpage-loading">
<img src="'.$this->pix_url('i/loading').'" />
<p>'.get_string('loading', 'repository').'</p>
</div>
</div>';
return preg_replace('/\{\!\}/', '', $rv);
}
/**
* FilePicker JS template for window appearing to select a file.
*
* All content must be enclosed in one element, CSS for this class must define width and
* height of the window;
*
* Thumbnail image will be added as content to the element with class 'fp-thumbnail';
*
* Inside the window the elements with the following classnames must be present:
* 'fp-saveas', 'fp-linktype-2', 'fp-linktype-1', 'fp-linktype-4', 'fp-setauthor',
* 'fp-setlicense'. Inside each of them must have one input element (or select in case of
* fp-setlicense). They may also have labels.
* The elements will be assign with class 'uneditable' and input/select element will become
* disabled if they are not applicable for the particular file;
*
* There may be present elements with classes 'fp-datemodified', 'fp-datecreated', 'fp-size',
* 'fp-license', 'fp-author', 'fp-dimensions'. They will receive additional class 'fp-unknown'
* if information is unavailable. If there is information available, the content of embedded
* element with class 'fp-value' will be substituted with the value;
*
* Elements with classes 'fp-select-confirm' and 'fp-select-cancel' will hold corresponding
* onclick events;
*
* When confirm button is pressed and file is being selected, the top element receives
* additional class 'loading'. It is removed when response from server is received.
*
* @return string
*/
private function fp_js_template_selectlayout() {
$rv = '
<div class="file-picker fp-select">
<div class="fp-select-loading">
<img src="'.$this->pix_url('i/loading').'" />
<p>'.get_string('loading', 'repository').'</p>
</div>
<form>
<div>
<a class="{!}fp-select-confirm fp-panel-button" href="#">'.get_string('getfile', 'repository').'</a>
<a class="{!}fp-select-cancel fp-panel-button" href="#">'.get_string('cancel').'</a>
</div>
<div class="fp-hr"></div>
<table>
<tr class="{!}fp-linktype-2">
<td></td>
<td class="mdl-left"><input type="radio"/><label>&nbsp;'.get_string('makefileinternal', 'repository').'</label></td></tr>
<tr class="{!}fp-linktype-1">
<td></td>
<td class="mdl-left"><input type="radio"/><label>&nbsp;'.get_string('makefilelink', 'repository').'</label></td></tr>
<tr class="{!}fp-linktype-4">
<td></td>
<td class="mdl-left"><input type="radio"/><label>&nbsp;'.get_string('makefilereference', 'repository').'</label></td></tr>
<tr class="{!}fp-saveas">
<td class="mdl-right"><label>'.get_string('saveas', 'repository').'</label>:</td>
<td class="mdl-left"><input type="text"/></td></tr>
<tr class="{!}fp-setauthor">
<td class="mdl-right"><label>'.get_string('author', 'repository').'</label>:</td>
<td class="mdl-left"><input type="text" /></td></tr>
<tr class="{!}fp-setlicense">
<td class="mdl-right"><label>'.get_string('chooselicense', 'repository').'</label>:</td>
<td class="mdl-left"><select></select></td></tr>
</table>
</form>
<p class="{!}fp-thumbnail"></p>
<div class="fp-fileinfo">
<div class="{!}fp-datemodified">'.get_string('lastmodified', 'moodle').': <span class="fp-value"/></div>
<div class="{!}fp-datecreated">'.get_string('datecreated', 'repository').': <span class="fp-value"/></div>
<div class="{!}fp-size">'.get_string('size', 'repository').': <span class="fp-value"/></div>
<div class="{!}fp-license">'.get_string('license', 'moodle').': <span class="fp-value"/></div>
<div class="{!}fp-author">'.get_string('author', 'repository').': <span class="fp-value"/></div>
<div class="{!}fp-dimensions">'.get_string('dimensions', 'repository').': <span class="fp-value"/></div>
</div>
</div>';
return preg_replace('/\{\!\}/', '', $rv);
}
/**
* FilePicker JS template for 'Upload file' repository
*
* Content to display when user chooses 'Upload file' repository (will be nested inside
* element with class 'fp-content').
*
* Must contain form (enctype="multipart/form-data" method="POST")
*
* The elements with the following classnames must be present:
* 'fp-file', 'fp-saveas', 'fp-setauthor', 'fp-setlicense'. Inside each of them must have
* one input element (or select in case of fp-setlicense). They may also have labels.
*
* Element with class 'fp-upload-btn' will hold onclick event for uploading the file;
*
* Please note that some fields may be hidden using CSS if this is part of quickupload form
*
* @return string
*/
private function fp_js_template_uploadform() {
$rv = '
<div class="fp-upload-form mdl-align">
<div class="fp-content-center">
<form enctype="multipart/form-data" method="POST">
<table >
<tr class="{!}fp-file">
<td class="mdl-right"><label>'.get_string('attachment', 'repository').'</label>:</td>
<td class="mdl-left"><input type="file"/></td></tr>
<tr class="{!}fp-saveas">
<td class="mdl-right"><label>'.get_string('saveas', 'repository').'</label>:</td>
<td class="mdl-left"><input type="text"/></td></tr>
<tr class="{!}fp-setauthor">
<td class="mdl-right"><label>'.get_string('author', 'repository').'</label>:</td>
<td class="mdl-left"><input type="text"/></td></tr>
<tr class="{!}fp-setlicense">
<td class="mdl-right"><label>'.get_string('chooselicense', 'repository').'</label>:</td>
<td class="mdl-left"><select/></td></tr>
</table>
</form>
<div><button class="{!}fp-upload-btn">'.get_string('upload', 'repository').'</button></div>
</div>
</div> ';
return preg_replace('/\{\!\}/', '', $rv);
}
/**
* FilePicker JS template to display during loading process (inside element with class 'fp-content').
*
* @return string
*/
private function fp_js_template_loading() {
return '
<div class="fp-content-loading">
<div class="fp-content-center">
<img src="'.$this->pix_url('i/loading').'" />
<p>'.get_string('loading', 'repository').'</p>
</div>
</div>';
}
/**
* FilePicker JS template for error (inside element with class 'fp-content').
*
* must have element with class 'fp-error', its content will be replaced with error text
* and the error code will be assigned as additional class to this element
* used errors: invalidjson, nofilesavailable, norepositoriesavailable
*
* @return string
*/
private function fp_js_template_error() {
$rv = '
<div class="fp-content-error" ><div class="{!}fp-error" /></div>';
return preg_replace('/\{\!\}/', '', $rv);
}
/**
* FilePicker JS template for error/info message displayed as a separate popup window.
*
* Must be wrapped in one element, CSS for this element must define
* width and height of the window. It will be assigned with an additional class 'fp-msg-error'
* or 'fp-msg-info' depending on message type;
*
* content of element with class 'fp-msg-text' will be replaced with error/info text;
*
* element with class 'fp-msg-butok' will hold onclick event
*
* @return string
*/
private function fp_js_template_message() {
$rv = '
<div class="file-picker fp-msg">
<p class="{!}fp-msg-text"></p>
<a class="{!}fp-msg-butok fp-panel-button" href="#">'.get_string('ok').'</a>
</div>';
return preg_replace('/\{\!\}/', '', $rv);
}
/**
* FilePicker JS template for popup dialogue window asking for action when file with the same name already exists.
*
* Must have one top element, CSS for this element must define width and height of the window;
*
* content of element with class 'fp-dlg-text' will be replaced with dialog text;
* elements with classes 'fp-dlg-butoverwrite', 'fp-dlg-butrename' and 'fp-dlg-butcancel' will
* hold onclick events;
*
* content of element with class 'fp-dlg-butrename' will be substituted with appropriate string
* (Note that it may have long text)
*
* @return string
*/
private function fp_js_template_processexistingfile() {
$rv = '
<div class="file-picker fp-dlg">
<p class="{!}fp-dlg-text"></p>
<a class="{!}fp-dlg-butoverwrite fp-panel-button" href="#">'.get_string('overwrite', 'repository').'</a>
<a class="{!}fp-dlg-butcancel fp-panel-button" href="#">'.get_string('cancel').'</a>
<a class="{!}fp-dlg-butrename fp-panel-button" href="#"/>
</div>';
return preg_replace('/\{\!\}/', '', $rv);
}
/**
* FilePicker JS template for repository login form including templates for each element type
*
* Must contain one <form> element with templates for different input types inside:
* Elements with classes 'fp-login-popup', 'fp-login-textarea', 'fp-login-select' and
* 'fp-login-input' are templates for displaying respective login form elements. Inside
* there must be exactly one element with type <button>, <textarea>, <select> or <input>
* (i.e. fp-login-popup should have <button>, fp-login-textarea should have <textarea>, etc.);
* They may also contain the <label> element and it's content will be substituted with
* label;
*
* You can also define elements with classes 'fp-login-checkbox', 'fp-login-text'
* but if they are not found, 'fp-login-input' will be used;
*
* Element with class 'fp-login-radiogroup' will be used for group of radio inputs. Inside
* it should hava a template for one radio input (with class 'fp-login-radio');
*
* Element with class 'fp-login-submit' will hold on click mouse event (form submission). It
* will be removed if at least one popup element is present;
*
* @return string
*/
private function fp_js_template_loginform() {
$rv = '
<div class="fp-login-form">
<div class="fp-content-center">
<form>
<table >
<tr class="{!}fp-login-popup">
<td colspan="2">
<label>'.get_string('popup', 'repository').'</label>
<p class="fp-popup"><button class="{!}fp-login-popup-but">'.get_string('login', 'repository').'</button></p></td></tr>
<tr class="{!}fp-login-textarea">
<td colspan="2"><p><textarea></textarea></p></td></tr>
<tr class="{!}fp-login-select">
<td align="right"><label></label></td>
<td align="left"><select></select></td></tr>
<tr class="{!}fp-login-input">
<td class="label"><label /></td>
<td class="input"><input/></td></tr>
<tr class="{!}fp-login-radiogroup">
<td align="right" width="30%" valign="top"><label /></td>
<td align="left" valign="top"><p class="{!}fp-login-radio"><input /> <label /></p></td></tr>
</table>
<p><button class="{!}fp-login-submit">'.get_string('submit', 'repository').'</button></p>
</form>
</div>
</div>';
return preg_replace('/\{\!\}/', '', $rv);
}
/**
* Returns all FilePicker JavaScript templates as an array.
*
* @return array
*/
public function filepicker_js_templates() {
$class_methods = get_class_methods($this);
$templates = array();
foreach ($class_methods as $method_name) {
if (preg_match('/^fp_js_template_(.*)$/', $method_name, $matches))
$templates[$matches[1]] = $this->$method_name();
}
return $templates;
}
/**
* Returns HTML for default repository searchform to be passed to Filepicker
*
* This will be used as contents for search form defined in generallayout template
* (form with id {TOOLSEARCHID}).
* Default contents is one text input field with name="s"
*/
public function repository_default_searchform() {
$str = '<input class="search-entry" name="s" value="Search" />';
return $str;
}
}
/**
* Data structure representing a general moodle file tree viewer
@ -148,8 +958,9 @@ class files_tree_viewer implements renderable {
$fileitem = array(
'params' => $params,
'filename' => $child->get_visible_name(),
'filedate' => $filedate ? userdate($filedate) : '',
'filesize' => $filesize ? display_size($filesize) : ''
'mimetype' => $child->get_mimetype(),
'filedate' => $filedate ? $filedate : '',
'filesize' => $filesize ? $filesize : ''
);
$url = new moodle_url('/files/index.php', $params);
if ($child->is_directory()) {

View File

@ -1049,6 +1049,7 @@ class grade_structure {
*/
public function get_element_icon(&$element, $spacerifnone=false) {
global $CFG, $OUTPUT;
require_once $CFG->libdir.'/filelib.php';
switch ($element['type']) {
case 'item':
@ -1114,7 +1115,7 @@ class grade_structure {
case 'category':
$strcat = get_string('category', 'grades');
return '<img src="'.$OUTPUT->pix_url('f/folder') . '" class="icon itemicon" ' .
return '<img src="'.$OUTPUT->pix_url(file_folder_icon()) . '" class="icon itemicon" ' .
'title="'.s($strcat).'" alt="'.s($strcat).'" />';
}

View File

@ -117,6 +117,9 @@ $string['errorinvalidformat'] = 'Unknown backup format';
$string['errorinvalidformatinfo'] = 'The selected file is not a valid Moodle backup file and can\'t be restored.';
$string['executionsuccess'] = 'The backup file was successfully created.';
$string['filename'] = 'Filename';
$string['filereferencesincluded'] = 'File references to external contents included in backup package, they won\'t work on other sites.';
$string['filereferencessamesite'] = 'Backup is from the same site, file references can be restored';
$string['filereferencesnotsamesite'] = 'Backup is from other site, file references cannot be restored';
$string['generalactivities'] = 'Include activities';
$string['generalanonymize'] = 'Anonymise information';
$string['generalbackdefaults'] = 'General backup defaults';
@ -148,6 +151,7 @@ $string['includeditems'] = 'Included items:';
$string['includesection'] = 'Section {$a}';
$string['includeuserinfo'] = 'User data';
$string['loglifetime'] = 'Keep logs for';
$string['includefilereferences'] = 'File references to external contents';
$string['locked'] = 'Locked';
$string['lockedbypermission'] = 'You don\'t have sufficient permissions to change this setting';
$string['lockedbyconfig'] = 'This setting has been locked by the default backup settings';

View File

@ -224,6 +224,7 @@ $string['errorsettinguserpref'] = 'Error setting user preference';
$string['errorunzippingfiles'] = 'Error unzipping files';
$string['expiredkey'] = 'Expired key';
$string['externalauthpassworderror'] = 'Non-empty password for external authentication';
$string['externalfilenolocation'] = 'External file has no location path';
$string['failtoloadblocks'] = 'One or more blocks are registered in the database, but they all failed to load!';
$string['fieldrequired'] = '"{$a}" is a required field';
$string['fileexists'] = 'File exists';
@ -323,6 +324,7 @@ $string['invalidsection'] = 'Course module record contains invalid section';
$string['invalidsesskey'] = 'Incorrect sesskey submitted, form not accepted!';
$string['invalidshortname'] = 'That\'s an invalid short course name';
$string['invalidstatedetected'] = 'Something has gone wrong: {$a}. This should never normally happen.';
$string['invalidsourcefield'] = 'Draft file\'s source field is invalid';
$string['invalidurl'] = 'Invalid URL';
$string['invaliduser'] = 'Invalid user';
$string['invaliduserid'] = 'Invalid user id';

View File

@ -18,6 +18,19 @@
/**
* Strings for component 'mimetypes', language 'en', branch 'MOODLE_20_STABLE'
*
* Strings are used to display human-readable name of mimetype. Some mimetypes share the same
* string. The following attributes are passed in the parameter when processing the string:
* $a->ext - filename extension in lower case
* $a->EXT - filename extension, capitalized
* $a->Ext - filename extension with first capital letter
* $a->mimetype - file mimetype
* $a->mimetype1 - first chunk of mimetype (before /)
* $a->mimetype2 - second chunk of mimetype (after /)
* $a->Mimetype, $a->MIMETYPE, $a->Mimetype1, $a->Mimetype2, $a->MIMETYPE1, $a->MIMETYPE2
* - the same with capitalized first/all letters
*
* @see get_mimetypes_array()
* @see get_mimetype_description()
* @package mimetypes
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
@ -25,15 +38,19 @@
$string['application/msword'] = 'Word document';
$string['application/pdf'] = 'PDF document';
$string['application/vnd.moodle.backup'] = 'Moodle backup';
$string['application/vnd.ms-excel'] = 'Excel spreadsheet';
$string['application/vnd.ms-powerpoint'] = 'Powerpoint presentation';
$string['application/zip'] = 'zip archive';
$string['audio/mp3'] = 'MP3 audio file';
$string['audio/wav'] = 'sound file';
$string['document/unknown'] = 'file';
$string['image/bmp'] = 'uncompressed BMP image';
$string['image/gif'] = 'GIF image';
$string['image/jpeg'] = 'JPEG image';
$string['image/png'] = 'PNG image';
$string['text/plain'] = 'text file';
$string['application/vnd.openxmlformats-officedocument.presentationml.presentation'] = 'Powerpoint presentation';
$string['application/vnd.openxmlformats-officedocument.presentationml.slideshow'] = 'Powerpoint slideshow';
$string['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'] = 'Excel spreadsheet';
$string['application/vnd.openxmlformats-officedocument.spreadsheetml.template'] = 'Excel template';
$string['application/vnd.openxmlformats-officedocument.wordprocessingml.document'] = 'Word document';
$string['archive'] = 'Archive ({$a->EXT})';
$string['audio'] = 'Audio file ({$a->EXT})';
$string['default'] = '{$a->mimetype}';
$string['document/unknown'] = 'File';
$string['image'] = 'Image ({$a->MIMETYPE2})';
$string['text/html'] = 'HTML document';
$string['text/plain'] = 'Text file';
$string['text/rtf'] = 'RTF document';

View File

@ -1249,6 +1249,7 @@ $string['olduserdirectory'] = 'This is the OLD users directory, and is no longer
$string['opentoguests'] = 'Guest access';
$string['optional'] = 'optional';
$string['order'] = 'Order';
$string['originalpath'] = 'Original path';
$string['orphanedactivities'] = 'Orphaned activities';
$string['other'] = 'Other';
$string['outline'] = 'Outline';

View File

@ -61,9 +61,15 @@ $string['commonrepositorysettings'] = 'Common repository settings';
$string['configallowexternallinks'] = 'This option enables all users to choose whether or not external media is copied into Moodle or not. If this is off then media is always copied into Moodle (this is usually best for overall data integrity and security). If this is on then users can choose each time they add media to a text.';
$string['configcacheexpire'] = 'The amount of time that file listings are cached locally (in seconds) when browsing external repositories.';
$string['configsaved'] = 'Configuration saved!';
$string['confirmdelete'] = 'Are you sure you want to delete this repository - {$a}?';
$string['confirmdelete'] = 'Are you sure you want to delete this repository - {$a}? If you choose "Continue and download", file references to external contents will be downloaded to moodle, but it could take long time to process.';
$string['confirmdeletefile'] = 'Are you sure you want to delete this file?';
$string['confirmremove'] = 'Are you sure you want to remove this repository plugin, its options and <strong>all of its instances</strong> - {$a}?';
$string['confirmrenamefile'] = 'Are you sure you want to rename/move this file? There are {$a} alias/shortcut files that use this file as their source. If you proceed then those aliases will be converted to true copies.';
$string['confirmdeletefilewithhref'] = 'Are you sure you want to delete this file? There are {$a} alias/shortcut files that use this file as their source. If you proceed then those aliases will be converted to true copies.';
$string['confirmdeletefolder'] = 'Are you sure you want to delete this folder? All files and subfolders will be deleted.';
$string['confirmremove'] = 'Are you sure you want to remove this repository plugin, its options and <strong>all of its instances</strong> - {$a}? If you choose "Continue and download", file references to external contents will be downloaded to moodle, but it could take long time to process.';
$string['confirmrenamefolder'] = ' Are you sure you want to move/rename this folder? Any alias/shortcut files that reference files in this folder will be converted into true copies.';
$string['continueuninstall'] = 'Continue';
$string['continueuninstallanddownload'] = 'Continue and download';
$string['copying'] = 'Copying';
$string['create'] = 'Create';
$string['createfolderfail'] = 'Fail to create this folder';
@ -72,8 +78,11 @@ $string['createinstance'] = 'Create a repository instance';
$string['createrepository'] = 'Create a repository instance';
$string['createxxinstance'] = 'Create "{$a}" instance';
$string['date'] = 'Date';
$string['datecreated'] = 'Created';
$string['deleted'] = 'Repository deleted';
$string['deleterepository'] = 'Delete this repository';
$string['detailview'] = 'View details';
$string['dimensions'] = 'Dimensions';
$string['disabled'] = 'Disabled';
$string['download'] = 'Download';
$string['downloadfolder'] = 'Download all';
@ -102,11 +111,15 @@ $string['filenotnull'] = 'You must select a file to upload.';
$string['filesaved'] = 'The file has been saved';
$string['filepicker'] = 'File picker';
$string['filesizenull'] = 'File size cannot be determined';
$string['folderexists'] = 'Folder name already being used, please use another name';
$string['foldernotfound'] = 'Folder not found';
$string['folderrecurse'] = 'Folder can not be moved to it\s own subfolder';
$string['getfile'] = 'Select this file';
$string['hidden'] = 'Hidden';
$string['choosealink'] = 'Choose a link...';
$string['chooselicense'] = 'Choose license';
$string['iconview'] = 'View as icons';
$string['imagesize'] = '{$a->width} x {$a->height} px';
$string['instance'] = 'instance';
$string['instancedeleted'] = 'Instance deleted';
$string['instances'] = 'Repository instances';
@ -117,6 +130,7 @@ $string['invalidjson'] = 'Invalid JSON string';
$string['invalidplugin'] = 'Invalid repository {$a} plug-in';
$string['invalidfiletype'] = '{$a} filetype cannot be accepted.';
$string['invalidrepositoryid'] = 'Invalid repository ID';
$string['invalidparams'] = 'Invalid parameters';
$string['isactive'] = 'Active?';
$string['keyword'] = 'Keyword';
$string['linkexternal'] = 'Link external';
@ -124,6 +138,9 @@ $string['listview'] = 'View as list';
$string['loading'] = 'Loading...';
$string['login'] = 'Login';
$string['logout'] = 'Logout';
$string['makefileinternal'] = 'Make a copy of the file';
$string['makefilelink'] = 'Link to the file directly';
$string['makefilereference'] = 'Create an alias/shortcut to the file';
$string['manage'] = 'Manage repositories';
$string['manageurl'] = 'Manage';
$string['manageuserrepository'] = 'Manage individual repository';
@ -139,6 +156,7 @@ $string['norepositoriesavailable'] = 'Sorry, none of your current repositories c
$string['norepositoriesexternalavailable'] = 'Sorry, none of your current repositories can return external files.';
$string['notyourinstances'] = 'You can not view/edit repository instances of another user';
$string['off'] = 'Enabled but hidden';
$string['original'] = 'Original';
$string['openpicker'] = 'Choose a file...';
$string['operation'] = 'Operation';
$string['on'] = 'Enabled and visible';
@ -150,10 +168,12 @@ $string['popup'] = 'Click "Login" button to login';
$string['popupblockeddownload'] = 'The downloading window is blocked, please allow the popup window, and try again.';
$string['preview'] = 'Preview';
$string['readonlyinstance'] = 'You cannot edit/delete a read-only instance';
$string['referencesexist'] = 'There are {$a} alias/shortcut files that use this file as their source';
$string['referenceslist'] = 'Aliases/Shortcuts';
$string['refresh'] = 'Refresh';
$string['refreshnonjsfilepicker'] = 'Please close this window and refresh non-javascript file picker';
$string['removed'] = 'Repository removed';
$string['renameto'] = 'Rename to';
$string['renameto'] = 'Rename to "{$a}"';
$string['repositories'] = 'Repositories';
$string['repository'] = 'Repository';
$string['repositorycourse'] = 'Course repositories';
@ -175,10 +195,14 @@ $string['submit'] = 'Submit';
$string['sync'] = 'Sync';
$string['thumbview'] = 'View as icons';
$string['title'] = 'Choose a file...';
$string['type'] = 'Type';
$string['typenotvisible'] = 'Type not visible';
$string['unknownoriginal'] = 'Unknown';
$string['upload'] = 'Upload this file';
$string['uploading'] = 'Uploading...';
$string['uploadsucc'] = 'The file has been uploaded successfully';
$string['undisclosedreference'] = '(Undisclosed)';
$string['uselatestfile'] = 'Use latest file';
$string['usercontextrepositorydisabled'] = 'You cannot edit this repository in user context';
$string['usenonjsfilemanager'] = 'Open file manager in new window';
$string['usenonjsfilepicker'] = 'Open file picker in new window';

View File

@ -403,9 +403,7 @@ function cron_run() {
cron_execute_plugin_type('format', 'course formats');
cron_execute_plugin_type('profilefield', 'profile fields');
cron_execute_plugin_type('webservice', 'webservices');
// TODO: Repository lib.php files are messed up (include many other files, etc), so it is
// currently not possible to implement repository plugin cron using this infrastructure
// cron_execute_plugin_type('repository', 'repository plugins');
cron_execute_plugin_type('repository', 'repository plugins');
cron_execute_plugin_type('qbehaviour', 'question behaviours');
cron_execute_plugin_type('qformat', 'question import/export formats');
cron_execute_plugin_type('qtype', 'question types');
@ -462,6 +460,9 @@ function cron_run() {
$fs = get_file_storage();
$fs->cron();
mtrace("Clean up cached external files");
// 1 week
cache_file::cleanup(array(), 60 * 60 * 24 * 7);
mtrace("Cron script completed correctly");

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="lib/db" VERSION="20120516" COMMENT="XMLDB file for core Moodle tables"
<XMLDB PATH="lib/db" VERSION="20120521" COMMENT="XMLDB file for core Moodle tables"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
>
@ -2326,7 +2326,7 @@
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="primary key of the table, please edit me"/>
</KEYS>
</TABLE>
<TABLE NAME="files" COMMENT="description of files, content is stored in sha1 file pool" PREVIOUS="message_working" NEXT="repository">
<TABLE NAME="files" COMMENT="description of files, content is stored in sha1 file pool" PREVIOUS="message_working" NEXT="files_reference">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" NEXT="contenthash"/>
<FIELD NAME="contenthash" TYPE="char" LENGTH="40" NOTNULL="true" SEQUENCE="false" COMMENT="sha1 hash of file content" PREVIOUS="id" NEXT="pathnamehash"/>
@ -2346,12 +2346,16 @@
<FIELD NAME="license" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" COMMENT="license of the file to guide reuse" PREVIOUS="author" NEXT="timecreated"/>
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" PREVIOUS="license" NEXT="timemodified"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" PREVIOUS="timecreated" NEXT="sortorder"/>
<FIELD NAME="sortorder" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="order of files" PREVIOUS="timemodified"/>
<FIELD NAME="sortorder" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="order of files" PREVIOUS="timemodified" NEXT="referencefileid"/>
<FIELD NAME="referencefileid" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="Use to indicate file is a proxy for repository file" PREVIOUS="sortorder" NEXT="referencelastsync"/>
<FIELD NAME="referencelastsync" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="Last time the proxy file was synced with repository, defined for performance reasons" PREVIOUS="referencefileid" NEXT="referencelifetime"/>
<FIELD NAME="referencelifetime" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="How often do we have to sync proxy file with repository, defined for performance reasons" PREVIOUS="referencelastsync"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="contextid"/>
<KEY NAME="contextid" TYPE="foreign" FIELDS="contextid" REFTABLE="context" REFFIELDS="id" PREVIOUS="primary" NEXT="userid"/>
<KEY NAME="userid" TYPE="foreign" FIELDS="userid" REFTABLE="user" REFFIELDS="id" PREVIOUS="contextid"/>
<KEY NAME="userid" TYPE="foreign" FIELDS="userid" REFTABLE="user" REFFIELDS="id" PREVIOUS="contextid" NEXT="referencefileid"/>
<KEY NAME="referencefileid" TYPE="foreign" FIELDS="referencefileid" REFTABLE="files_reference" REFFIELDS="id" PREVIOUS="userid"/>
</KEYS>
<INDEXES>
<INDEX NAME="component-filearea-contextid-itemid" UNIQUE="false" FIELDS="component, filearea, contextid, itemid" NEXT="contenthash"/>
@ -2359,7 +2363,20 @@
<INDEX NAME="pathnamehash" UNIQUE="true" FIELDS="pathnamehash" PREVIOUS="contenthash"/>
</INDEXES>
</TABLE>
<TABLE NAME="repository" COMMENT="This table contains one entry for every configured external repository instance." PREVIOUS="files" NEXT="repository_instances">
<TABLE NAME="files_reference" COMMENT="Store files references" PREVIOUS="files" NEXT="repository">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" NEXT="repositoryid"/>
<FIELD NAME="repositoryid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" PREVIOUS="id" NEXT="lastsync"/>
<FIELD NAME="lastsync" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="Last time the proxy file was synced with repository" PREVIOUS="repositoryid" NEXT="lifetime"/>
<FIELD NAME="lifetime" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="How often do we have to sync proxy file with repository" PREVIOUS="lastsync" NEXT="reference"/>
<FIELD NAME="reference" TYPE="text" NOTNULL="false" SEQUENCE="false" PREVIOUS="lifetime"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="repositoryid"/>
<KEY NAME="repositoryid" TYPE="foreign" FIELDS="repositoryid" REFTABLE="repository_instances" REFFIELDS="id" PREVIOUS="primary"/>
</KEYS>
</TABLE>
<TABLE NAME="repository" COMMENT="This table contains one entry for every configured external repository instance." PREVIOUS="files_reference" NEXT="repository_instances">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" NEXT="type"/>
<FIELD NAME="type" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="id" NEXT="visible"/>

View File

@ -592,5 +592,61 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2012051100.03);
}
if ($oldversion < 2012052100.00) {
// Define field referencefileid to be added to files.
$table = new xmldb_table('files');
// Define field referencefileid to be added to files.
$field = new xmldb_field('referencefileid', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'sortorder');
// Conditionally launch add field referencefileid.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Define field referencelastsync to be added to files.
$field = new xmldb_field('referencelastsync', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'referencefileid');
// Conditionally launch add field referencelastsync.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Define field referencelifetime to be added to files.
$field = new xmldb_field('referencelifetime', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'referencelastsync');
// Conditionally launch add field referencelifetime.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
$key = new xmldb_key('referencefileid', XMLDB_KEY_FOREIGN, array('referencefileid'), 'files_reference', array('id'));
// Launch add key referencefileid
$dbman->add_key($table, $key);
// Define table files_reference to be created.
$table = new xmldb_table('files_reference');
// Adding fields to table files_reference.
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('repositoryid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
$table->add_field('lastsync', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
$table->add_field('lifetime', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
$table->add_field('reference', XMLDB_TYPE_TEXT, null, null, null, null, null);
// Adding keys to table files_reference.
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->add_key('repositoryid', XMLDB_KEY_FOREIGN, array('repositoryid'), 'repository_instances', array('id'));
// Conditionally launch create table for files_reference
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}
// Main savepoint reached
upgrade_main_savepoint(true, 2012052100.00);
}
return true;
}

View File

@ -226,6 +226,20 @@ abstract class file_info {
return 0;
}
/**
* Returns the localised human-readable name of the file together with
* virtual path
*
* @return string
*/
public function get_readable_fullname() {
$fpath = array();
for ($parent = $this; $parent; $parent = $parent->get_parent()) {
array_unshift($fpath, $parent->get_visible_name());
}
return join('/', $fpath);
}
/**
* Create new directory, may throw exception - make sure
* params are valid.

View File

@ -201,7 +201,7 @@ class file_info_context_user extends file_info {
return null;
}
}
$urlbase = $CFG->wwwroot.'/pluginfile.php';
$urlbase = $CFG->wwwroot.'/draftfile.php';
return new file_info_stored($this->browser, $this->context, $storedfile, $urlbase, get_string('areauserdraft', 'repository'), true, true, true, true);
}

View File

@ -187,6 +187,16 @@ class file_info_stored extends file_info {
return $this->lf->get_filesize();
}
/**
* Returns width, height and mimetype of the stored image, or false
*
* @see stored_file::get_imageinfo()
* @return array|false
*/
public function get_imageinfo() {
return $this->lf->get_imageinfo();
}
/**
* Returns mimetype
*

File diff suppressed because it is too large Load Diff

View File

@ -65,7 +65,7 @@ class stored_file_creation_exception extends file_exception {
* @param string $filename file name
* @param string $debuginfo extra debug info
*/
function __construct($contextid, $component, $filearea, $itemid, $filepath, $filename, $debuginfo = NULL) {
function __construct($contextid, $component, $filearea, $itemid, $filepath, $filename, $debuginfo = null) {
$a = new stdClass();
$a->contextid = $contextid;
$a->component = $component;
@ -91,8 +91,8 @@ class file_access_exception extends file_exception {
*
* @param string $debuginfo extra debug info
*/
function __construct($debuginfo = NULL) {
parent::__construct('nopermissions', NULL, $debuginfo);
public function __construct($debuginfo = null) {
parent::__construct('nopermissions', null, $debuginfo);
}
}
@ -111,7 +111,28 @@ class file_pool_content_exception extends file_exception {
* @param string $contenthash content hash
* @param string $debuginfo extra debug info
*/
function __construct($contenthash, $debuginfo = NULL) {
public function __construct($contenthash, $debuginfo = null) {
parent::__construct('hashpoolproblem', $contenthash, $debuginfo);
}
}
/**
* Exception related to external file support
*
* @package core_files
* @category files
* @copyright 2012 Dongsheng Cai {@link http://dongsheng.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class external_file_exception extends file_exception {
/**
* Constructor
*
* @param string $errorcode error code
* @param stdClass $a extra information
* @param string $debuginfo extra debug info
*/
public function __construct($errorcode, $a = null, $debuginfo = null) {
parent::__construct($errorcode, '', '', $a, $debuginfo);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,112 +0,0 @@
<map version="0.7.1">
<node ID="_Freemind_Link_1016958583" TEXT="Root">
<node TEXT="image" POSITION="right">
<node TEXT="web_image">
<node ID="_Freemind_Link_750128103" TEXT=".jpg"/>
<node ID="_Freemind_Link_1840944189" TEXT=".png"/>
<node ID="_Freemind_Link_1710862996" TEXT=".gif"/>
</node>
<node TEXT="non_web_image">
<node ID="_Freemind_Link_481322493" TEXT=".bmp"/>
<node ID="_Freemind_Link_1948466853" TEXT=".svg"/>
<node ID="_Freemind_Link_82277447" TEXT=".psd"/>
</node>
</node>
<node TEXT="audio" POSITION="left">
<node ID="_Freemind_Link_606456130" TEXT="web_audio">
<node ID="_Freemind_Link_59286792" TEXT=".wav"/>
<node ID="_Freemind_Link_618796935" TEXT=".mp3"/>
<node ID="_Freemind_Link_313976796" TEXT=".ra"/>
<node ID="_Freemind_Link_709595453" TEXT=".wma"/>
<node TEXT=".ogg"/>
<node ID="ID_421461117" TEXT=".aac"/>
</node>
<node ID="_Freemind_Link_1800832653" TEXT="non_web_audio">
<node ID="_Freemind_Link_1772266185" TEXT=".ape"/>
<node ID="_Freemind_Link_964578090" TEXT=".au"/>
<node ID="_Freemind_Link_1295244579" TEXT=".mid"/>
</node>
</node>
<node ID="_Freemind_Link_70165685" TEXT="video" POSITION="right">
<node ID="_Freemind_Link_164412832" TEXT="web_video">
<node ID="_Freemind_Link_1674188247" TEXT=".flv"/>
<node ID="_Freemind_Link_1109951130" TEXT=".swf"/>
<node ID="_Freemind_Link_441200481" TEXT=".mov"/>
<node ID="_Freemind_Link_1073677924" TEXT=".rm"/>
<node ID="_Freemind_Link_810187762" TEXT=".wmv"/>
<node ID="_Freemind_Link_763870397" TEXT=".asf"/>
<node TEXT=".ogv"/>
<node TEXT=".f4v"/>
<node TEXT=".m4v"/>
<node TEXT=".webm"/>
</node>
<node ID="_Freemind_Link_1019644700" TEXT="non_web_video">
<node ID="_Freemind_Link_190589975" TEXT=".avi"/>
<node ID="_Freemind_Link_1728963308" TEXT=".mpg"/>
<node ID="_Freemind_Link_761274675" TEXT=".mp4"/>
</node>
</node>
<node ID="_Freemind_Link_1159259702" TEXT="document" POSITION="left">
<node ID="_Freemind_Link_395227081" TEXT="msoffice">
<node ID="_Freemind_Link_1480546733" TEXT=".doc"/>
<node ID="_Freemind_Link_983591781" TEXT=".ppt"/>
<node ID="_Freemind_Link_922920573" TEXT=".xls"/>
</node>
<node TEXT="openoffice">
<node ID="_Freemind_Link_368708997" TEXT=".odt"/>
<node ID="_Freemind_Link_725490871" TEXT=".odp"/>
</node>
<node ID="_Freemind_Link_1253224142" TEXT="other">
<node ID="_Freemind_Link_1202332406" TEXT=".pdf"/>
<node ID="_Freemind_Link_1229438606" TEXT=".ps"/>
</node>
</node>
<node ID="_Freemind_Link_525709024" TEXT="text" POSITION="right">
<node ID="_Freemind_Link_1252355401" TEXT="source">
<node ID="_Freemind_Link_1783454794" TEXT=".c"/>
<node ID="_Freemind_Link_603295666" TEXT=".cpp"/>
<node ID="_Freemind_Link_1939719884" TEXT=".java"/>
</node>
<node TEXT="script">
<node ID="_Freemind_Link_567551283" TEXT=".php"/>
<node ID="_Freemind_Link_829963573" TEXT=".py"/>
<node ID="_Freemind_Link_699741325" TEXT=".lua"/>
<node ID="_Freemind_Link_841176112" TEXT=".rb"/>
</node>
<node ID="_Freemind_Link_466282865" TEXT="markup">
<node ID="_Freemind_Link_776860364" TEXT=".xml"/>
<node ID="_Freemind_Link_428374654" TEXT=".html"/>
<node ID="_Freemind_Link_1636201602" TEXT=".xhtml"/>
</node>
<node TEXT="plaintext">
<node ID="_Freemind_Link_304679617" TEXT=".txt"/>
<node ID="_Freemind_Link_988584709" TEXT=".log"/>
<node ID="_Freemind_Link_778232964" TEXT=".csv"/>
</node>
</node>
<node ID="_Freemind_Link_329759178" TEXT="moodle" POSITION="left">
<node ID="_Freemind_Link_864349088" TEXT=".mb.zip"/>
<node ID="_Freemind_Link_1509389480" TEXT=".ld.zip"/>
</node>
<node ID="_Freemind_Link_907467024" TEXT="archive" POSITION="right">
<node ID="_Freemind_Link_637157755" TEXT=".rar"/>
<node ID="_Freemind_Link_628673054" TEXT=".cab"/>
<node ID="_Freemind_Link_1141513740" TEXT=".iso"/>
<node ID="_Freemind_Link_1269400334" TEXT=".img"/>
<node ID="_Freemind_Link_1973736841" TEXT=".tar.gz"/>
<node ID="_Freemind_Link_1525022758" TEXT=".zip"/>
</node>
<node ID="_Freemind_Link_1332471247" TEXT="application" POSITION="left">
<node TEXT="windows">
<node ID="_Freemind_Link_1154060414" TEXT=".exe"/>
<node ID="_Freemind_Link_1578063867" TEXT=".dll"/>
</node>
<node TEXT="linux">
<node ID="_Freemind_Link_68848485" TEXT=".bin"/>
</node>
<node ID="_Freemind_Link_317684862" TEXT="mac">
<node ID="_" TEXT=".app"/>
</node>
</node>
</node>
</map>

View File

@ -25,7 +25,7 @@
defined('MOODLE_INTERNAL') || die();
require_once("$CFG->libdir/filestorage/stored_file.php");
require_once("$CFG->dirroot/repository/lib.php");
/**
* Class representing local files stored in a sha1 file pool.
@ -42,10 +42,12 @@ require_once("$CFG->libdir/filestorage/stored_file.php");
class stored_file {
/** @var file_storage file storage pool instance */
private $fs;
/** @var stdClass record from the files table */
/** @var stdClass record from the files table left join files_reference table */
private $file_record;
/** @var string location of content files */
private $filedir;
/** @var repository repository plugin instance */
public $repository;
/**
* Constructor, this constructor should be called ONLY from the file_storage class!
@ -55,9 +57,172 @@ class stored_file {
* @param string $filedir location of file directory with sh1 named content files
*/
public function __construct(file_storage $fs, stdClass $file_record, $filedir) {
global $DB, $CFG;
$this->fs = $fs;
$this->file_record = clone($file_record); // prevent modifications
$this->filedir = $filedir; // keep secret, do not expose!
if (!empty($file_record->repositoryid)) {
$this->repository = repository::get_repository_by_id($file_record->repositoryid, SYSCONTEXTID);
if ($this->repository->supported_returntypes() & FILE_REFERENCE != FILE_REFERENCE) {
// Repository cannot do file reference.
throw new moodle_exception('error');
}
} else {
$this->repository = null;
}
}
/**
* Whether or not this is a external resource
*
* @return bool
*/
public function is_external_file() {
return !empty($this->repository);
}
/**
* Update some file record fields
* NOTE: Must remain protected
*
* @param stdClass $dataobject
*/
protected function update($dataobject) {
global $DB;
$keys = array_keys((array)$this->file_record);
foreach ($dataobject as $field => $value) {
if (in_array($field, $keys)) {
if ($field == 'contextid' and (!is_number($value) or $value < 1)) {
throw new file_exception('storedfileproblem', 'Invalid contextid');
}
if ($field == 'component') {
$value = clean_param($value, PARAM_COMPONENT);
if (empty($value)) {
throw new file_exception('storedfileproblem', 'Invalid component');
}
}
if ($field == 'filearea') {
$value = clean_param($value, PARAM_AREA);
if (empty($value)) {
throw new file_exception('storedfileproblem', 'Invalid filearea');
}
}
if ($field == 'itemid' and (!is_number($value) or $value < 0)) {
throw new file_exception('storedfileproblem', 'Invalid itemid');
}
if ($field == 'filepath') {
$value = clean_param($value, PARAM_PATH);
if (strpos($value, '/') !== 0 or strrpos($value, '/') !== strlen($value)-1) {
// path must start and end with '/'
throw new file_exception('storedfileproblem', 'Invalid file path');
}
}
if ($field == 'filename') {
// folder has filename == '.', so we pass this
if ($value != '.') {
$value = clean_param($value, PARAM_FILE);
}
if ($value === '') {
throw new file_exception('storedfileproblem', 'Invalid file name');
}
}
if ($field === 'timecreated' or $field === 'timemodified') {
if (!is_number($value)) {
throw new file_exception('storedfileproblem', 'Invalid timestamp');
}
if ($value < 0) {
$value = 0;
}
}
if ($field == 'referencefileid' or $field == 'referencelastsync' or $field == 'referencelifetime') {
$value = clean_param($value, PARAM_INT);
}
// adding the field
$this->file_record->$field = $value;
} else {
throw new coding_exception("Invalid field name, $field doesn't exist in file record");
}
}
// Validate mimetype field
// we don't use {@link stored_file::get_content_file_location()} here becaues it will try to update file_record
$pathname = $this->get_pathname_by_contenthash();
// try to recover the content from trash
if (!is_readable($pathname)) {
if (!$this->fs->try_content_recovery($this) or !is_readable($pathname)) {
throw new file_exception('storedfilecannotread', '', $pathname);
}
}
$mimetype = $this->fs->mimetype($pathname);
$this->file_record->mimetype = $mimetype;
$DB->update_record('files', $this->file_record);
}
/**
* Rename filename
*
* @param string $filepath file path
* @param string $filename file name
*/
public function rename($filepath, $filename) {
if ($this->fs->file_exists($this->get_contextid(), $this->get_component(), $this->get_filearea(), $this->get_itemid(), $filepath, $filename)) {
throw new file_exception('storedfilenotcreated', '', 'file exists, cannot rename');
}
$filerecord = new stdClass;
$filerecord->filepath = $filepath;
$filerecord->filename = $filename;
// populate the pathname hash
$filerecord->pathnamehash = $this->fs->get_pathname_hash($this->file_record->contextid, $this->file_record->component, $this->file_record->filearea, $this->file_record->itemid, $filepath, $filename);
$this->update($filerecord);
}
/**
* Replace the content by providing another stored_file instance
*
* @param stored_file $storedfile
*/
public function replace_content_with(stored_file $storedfile) {
$contenthash = $storedfile->get_contenthash();
$this->set_contenthash($contenthash);
}
/**
* Delete file reference
*
*/
public function delete_reference() {
global $DB;
// Remove repository info.
$this->repository = null;
// Remove reference info from DB.
$DB->delete_records('files_reference', array('id'=>$this->file_record->referencefileid));
// Must refresh $this->file_record form DB
$filerecord = $DB->get_record('files', array('id'=>$this->get_id()));
// Update DB
$filerecord->referencelastsync = null;
$filerecord->referencelifetime = null;
$filerecord->referencefileid = null;
$this->update($filerecord);
// unset object variable
unset($this->file_record->repositoryid);
unset($this->file_record->reference);
unset($this->file_record->referencelastsync);
unset($this->file_record->referencelifetime);
unset($this->file_record->referencefileid);
}
/**
@ -83,13 +248,39 @@ class stored_file {
*/
public function delete() {
global $DB;
// If other files referring to this file, we need convert them
if ($files = $this->fs->get_references_by_storedfile($this)) {
foreach ($files as $file) {
$this->fs->import_external_file($file);
}
}
// Now delete file records in DB
$DB->delete_records('files', array('id'=>$this->file_record->id));
$DB->delete_records('files_reference', array('id'=>$this->file_record->referencefileid));
// moves pool file to trash if content not needed any more
$this->fs->deleted_file_cleanup($this->file_record->contenthash);
return true; // BC only
}
/**
* Get file pathname by contenthash
*
* NOTE, this function is not calling sync_external_file, it assume the contenthash is current
* Protected - developers must not gain direct access to this function.
*
* @return string full path to pool file with file content
*/
protected function get_pathname_by_contenthash() {
// Detect is local file or not.
$contenthash = $this->file_record->contenthash;
$l1 = $contenthash[0].$contenthash[1];
$l2 = $contenthash[2].$contenthash[3];
return "$this->filedir/$l1/$l2/$contenthash";
}
/**
* Get file pathname by given contenthash, this method will try to sync files
*
* Protected - developers must not gain direct access to this function.
*
* NOTE: do not make this public, we must not modify or delete the pool files directly! ;-)
@ -97,10 +288,8 @@ class stored_file {
* @return string full path to pool file with file content
**/
protected function get_content_file_location() {
$contenthash = $this->file_record->contenthash;
$l1 = $contenthash[0].$contenthash[1];
$l2 = $contenthash[2].$contenthash[3];
return "$this->filedir/$l1/$l2/$contenthash";
$this->sync_external_file();
return $this->get_pathname_by_contenthash();
}
/**
@ -128,7 +317,7 @@ class stored_file {
throw new file_exception('storedfilecannotread', '', $path);
}
}
return fopen($path, 'rb'); //binary reading only!!
return fopen($path, 'rb'); // Binary reading only!!
}
/**
@ -241,7 +430,14 @@ class stored_file {
* @return mixed array with width, height and mimetype; false if not an image
*/
public function get_imageinfo() {
if (!$imageinfo = getimagesize($this->get_content_file_location())) {
$path = $this->get_content_file_location();
if (!is_readable($path)) {
if (!$this->fs->try_content_recovery($this) or !is_readable($path)) {
throw new file_exception('storedfilecannotread', '', $path);
}
}
$mimetype = $this->get_mimetype();
if (!preg_match('|^image/|', $mimetype) || !filesize($path) || !($imageinfo = getimagesize($path))) {
return false;
}
$image = array('width'=>$imageinfo[0], 'height'=>$imageinfo[1], 'mimetype'=>image_type_to_mime_type($imageinfo[2]));
@ -261,7 +457,7 @@ class stored_file {
*/
public function is_valid_image() {
$mimetype = $this->get_mimetype();
if ($mimetype !== 'image/gif' and $mimetype !== 'image/jpeg' and $mimetype !== 'image/png') {
if (!file_mimetype_in_typegroup($mimetype, 'web_image')) {
return false;
}
if (!$info = $this->get_imageinfo()) {
@ -300,7 +496,33 @@ class stored_file {
}
/**
* Returns context id of the file-
* Sync external files
*
* @return bool true if file content changed, false if not
*/
public function sync_external_file() {
global $CFG, $DB;
if (empty($this->file_record->referencefileid)) {
return false;
}
if (empty($this->file_record->referencelastsync) or ($this->file_record->referencelastsync + $this->file_record->referencelifetime < time())) {
require_once($CFG->dirroot.'/repository/lib.php');
if (repository::sync_external_file($this)) {
$prevcontent = $this->file_record->contenthash;
$sql = "SELECT f.*, r.repositoryid, r.reference
FROM {files} f
LEFT JOIN {files_reference} r
ON f.referencefileid = r.id
WHERE f.id = ?";
$this->file_record = $DB->get_record_sql($sql, array($this->file_record->id), MUST_EXIST);
return ($prevcontent !== $this->file_record->contenthash);
}
}
return false;
}
/**
* Returns context id of the file
*
* @return int context id
*/
@ -370,9 +592,21 @@ class stored_file {
* @return int bytes
*/
public function get_filesize() {
$this->sync_external_file();
return $this->file_record->filesize;
}
/**
* Returns the size of file in bytes.
*
* @param int $filesize bytes
*/
public function set_filesize($filesize) {
$filerecord = new stdClass;
$filerecord->filesize = $filesize;
$this->update($filerecord);
}
/**
* Returns mime type of file.
*
@ -397,9 +631,21 @@ class stored_file {
* @return int
*/
public function get_timemodified() {
$this->sync_external_file();
return $this->file_record->timemodified;
}
/**
* set timemodified
*
* @param int $timemodified
*/
public function set_timemodified($timemodified) {
$filerecord = new stdClass;
$filerecord->timemodified = $timemodified;
$this->update($filerecord);
}
/**
* Returns file status flag.
*
@ -424,9 +670,26 @@ class stored_file {
* @return string
*/
public function get_contenthash() {
$this->sync_external_file();
return $this->file_record->contenthash;
}
/**
* Set contenthash
*
* @param string $contenthash
*/
protected function set_contenthash($contenthash) {
// make sure the content exists in moodle file pool
if ($this->fs->content_exists($contenthash)) {
$filerecord = new stdClass;
$filerecord->contenthash = $contenthash;
$this->update($filerecord);
} else {
throw new file_exception('storedfileproblem', 'Invalid contenthash, content must be already in filepool', $contenthash);
}
}
/**
* Returns sha1 hash of all file path components sha1("contextid/component/filearea/itemid/dir/dir/filename.ext").
*
@ -445,6 +708,17 @@ class stored_file {
return $this->file_record->license;
}
/**
* Set license
*
* @param string $license license
*/
public function set_license($license) {
$filerecord = new stdClass;
$filerecord->license = $license;
$this->update($filerecord);
}
/**
* Returns the author name of the file.
*
@ -454,6 +728,17 @@ class stored_file {
return $this->file_record->author;
}
/**
* Set author
*
* @param string $author
*/
public function set_author($author) {
$filerecord = new stdClass;
$filerecord->author = $author;
$this->update($filerecord);
}
/**
* Returns the source of the file, usually it is a url.
*
@ -463,6 +748,18 @@ class stored_file {
return $this->file_record->source;
}
/**
* Set license
*
* @param string $license license
*/
public function set_source($source) {
$filerecord = new stdClass;
$filerecord->source = $source;
$this->update($filerecord);
}
/**
* Returns the sort order of file
*
@ -471,4 +768,82 @@ class stored_file {
public function get_sortorder() {
return $this->file_record->sortorder;
}
/**
* Set file sort order
*
* @param int $sortorder
* @return int
*/
public function set_sortorder($sortorder) {
$filerecord = new stdClass;
$filerecord->sortorder = $sortorder;
$this->update($filerecord);
}
/**
* Returns repository id
*
* @return int|null
*/
public function get_repository_id() {
if (!empty($this->repository)) {
return $this->repository->id;
} else {
return null;
}
}
/**
* get reference file id
* @return int
*/
public function get_referencefileid() {
return $this->file_record->referencefileid;
}
/**
* Get reference last sync time
* @return int
*/
public function get_referencelastsync() {
return $this->file_record->referencelastsync;
}
/**
* Get reference last sync time
* @return int
*/
public function get_referencelifetime() {
return $this->file_record->referencelifetime;
}
/**
* Returns file reference
*
* @return string
*/
public function get_reference() {
return $this->file_record->reference;
}
/**
* Get human readable file reference information
*
* @return string
*/
public function get_reference_details() {
return $this->repository->get_reference_details($this->get_reference());
}
/**
* Send file references
*
* @param int $lifetime Number of seconds before the file should expire from caches (default 24 hours)
* @param int $filter 0 (default)=no filtering, 1=all files, 2=html files only
* @param bool $forcedownload If true (default false), forces download of file rather than view in browser/plugin
* @param array $options additional options affecting the file serving
*/
public function send_file($lifetime, $filter, $forcedownload, $options) {
$this->repository->send_file($this, $lifetime, $filter, $forcedownload, $options);
}
}

View File

@ -77,4 +77,134 @@ class filestoragelib_testcase extends advanced_testcase {
$this->assertInstanceOf('stored_file', $previewtinyicon);
$this->assertEquals('6b9864ae1536a8eeef54e097319175a8be12f07c', $previewtinyicon->get_filename());
}
/**
* Make sure renaming is working
*
* @copyright 2012 Dongsheng Cai {@link http://dongsheng.org}
*/
public function test_file_renaming() {
global $CFG;
$this->resetAfterTest(true);
$fs = get_file_storage();
$syscontext = context_system::instance();
$component = 'core';
$filearea = 'unittest';
$itemid = 0;
$filepath = '/';
$filename = 'test.txt';
$filerecord = array(
'contextid' => $syscontext->id,
'component' => $component,
'filearea' => $filearea,
'itemid' => $itemid,
'filepath' => $filepath,
'filename' => $filename,
);
$originalfile = $fs->create_file_from_string($filerecord, 'Test content');
$this->assertInstanceOf('stored_file', $originalfile);
$contenthash = $originalfile->get_contenthash();
$newpath = '/test/';
$newname = 'newtest.txt';
// this should work
$originalfile->rename($newpath, $newname);
$file = $fs->get_file($syscontext->id, $component, $filearea, $itemid, $newpath, $newname);
$this->assertInstanceOf('stored_file', $file);
$this->assertEquals($contenthash, $file->get_contenthash());
// try break it
$this->setExpectedException('file_exception');
// this shall throw exception
$originalfile->rename($newpath, $newname);
}
/**
* Create file from reference tests
*
* @copyright 2012 Dongsheng Cai {@link http://dongsheng.org}
*/
public function test_create_file_from_reference() {
global $CFG, $DB;
$this->resetAfterTest(true);
// create user
$generator = $this->getDataGenerator();
$user = $generator->create_user();
$usercontext = context_user::instance($user->id);
$syscontext = context_system::instance();
$USER = $DB->get_record('user', array('id'=>$user->id));
$fs = get_file_storage();
$repositorypluginname = 'user';
// override repository permission
$capability = 'repository/' . $repositorypluginname . ':view';
$allroles = $DB->get_records_menu('role', array(), 'id', 'archetype, id');
assign_capability($capability, CAP_ALLOW, $allroles['guest'], $syscontext->id, true);
$args = array();
$args['type'] = $repositorypluginname;
$repos = repository::get_instances($args);
$userrepository = reset($repos);
$this->assertInstanceOf('repository', $userrepository);
$component = 'user';
$filearea = 'private';
$itemid = 0;
$filepath = '/';
$filename = 'userfile.txt';
$filerecord = array(
'contextid' => $usercontext->id,
'component' => $component,
'filearea' => $filearea,
'itemid' => $itemid,
'filepath' => $filepath,
'filename' => $filename,
);
$content = 'Test content';
$originalfile = $fs->create_file_from_string($filerecord, $content);
$this->assertInstanceOf('stored_file', $originalfile);
$newfilerecord = array(
'contextid' => $syscontext->id,
'component' => 'core',
'filearea' => 'phpunit',
'itemid' => 0,
'filepath' => $filepath,
'filename' => $filename,
);
$ref = $fs->pack_reference($filerecord);
$newstoredfile = $fs->create_file_from_reference($newfilerecord, $userrepository->id, $ref);
$this->assertInstanceOf('stored_file', $newstoredfile);
$this->assertEquals($userrepository->id, $newstoredfile->repository->id);
$this->assertEquals($originalfile->get_contenthash(), $newstoredfile->get_contenthash());
$this->assertEquals($originalfile->get_filesize(), $newstoredfile->get_filesize());
$this->assertRegExp('#' . $filename. '$#', $newstoredfile->get_reference_details());
// Test looking for references
$count = $fs->get_references_count_by_storedfile($originalfile);
$this->assertEquals(1, $count);
$files = $fs->get_references_by_storedfile($originalfile);
$file = reset($files);
$this->assertEquals($file, $newstoredfile);
// Look for references by repository ID
$files = $fs->get_external_files($userrepository->id);
$file = reset($files);
$this->assertEquals($file, $newstoredfile);
// Try convert reference to local file
$importedfile = $fs->import_external_file($newstoredfile);
$this->assertFalse($importedfile->is_external_file());
$this->assertInstanceOf('stored_file', $importedfile);
// still readable?
$this->assertEquals($content, $importedfile->get_content());
}
}

View File

@ -64,18 +64,20 @@ M.form_dndupload.init = function(Y, options) {
* maxfiles: maximum number of files this form allows
* maxbytes: maximum size of files allowed in this form
* clientid: unqiue id of this form field used for html elements
* containerprefix: prefix of htmlid of container
* containerid: htmlid of container
* repositories: array of repository objects passed from filepicker
* filemanager: filemanager element we are working with
* callback: callback to filepicker element to refesh when uploaded
* formcallback: callback to filepicker element to refesh when uploaded
* }
*/
init: function(Y, options) {
this.Y = Y;
if (!this.browser_supported()) {
Y.one('body').addClass('dndnotsupported');
return; // Browser does not support the required functionality
}
Y.one('body').addClass('dndsupported');
// try and retrieve enabled upload repository
this.repositoryid = this.get_upload_repositoryid(options.repositories);
@ -89,21 +91,12 @@ M.form_dndupload.init = function(Y, options) {
this.maxfiles = options.maxfiles;
this.maxbytes = options.maxbytes;
this.itemid = options.itemid;
this.container = this.Y.one(options.containerprefix + this.clientid);
this.container = this.Y.one('#'+options.containerid);
if (options.filemanager) {
// Needed to tell the filemanager to redraw when files uploaded
// and to check how many files are already uploaded
this.filemanager = options.filemanager;
// Add a callback to show the 'drag and drop enabled' message
// within the filemanager box once it has finished loading,
// if there are no files yet uploaded
this.filemanager.emptycallback = function(clientid) {
var el = Y.one('#dndenabled2-'+clientid);
if (el) {
el.setStyle('display', 'inline');
}
}
} else if (options.formcallback) {
// Needed to tell the filepicker to update when a new
@ -111,14 +104,13 @@ M.form_dndupload.init = function(Y, options) {
this.callback = options.formcallback;
} else {
if (M.cfg.developerdebug) {
alert('dndupload: Need to define either options.filemanager or options.callback');
alert('dndupload: Need to define either options.filemanager or options.formcallback');
}
return;
}
this.init_events();
this.init_page_events();
this.Y.one('#dndenabled-'+this.clientid).setStyle('display', 'inline');
},
/**
@ -361,11 +353,11 @@ M.form_dndupload.init = function(Y, options) {
* Highlight the area where files could be dropped
*/
show_drop_target: function() {
this.Y.one('#filemanager-uploadmessage'+this.clientid).setStyle('display', 'block');
this.container.addClass('dndupload-ready');
},
hide_drop_target: function() {
this.Y.one('#filemanager-uploadmessage'+this.clientid).setStyle('display', 'none');
this.container.removeClass('dndupload-ready');
},
/**
@ -386,20 +378,14 @@ M.form_dndupload.init = function(Y, options) {
* Display a progress spinner in the destination node
*/
show_progress_spinner: function() {
// add a loading spinner to show something is happening
var loadingspinner = this.Y.Node.create('<div id="dndprogresspinner-'+this.clientid+'" style="text-align: center">');
loadingspinner.append('<img src="'+M.util.image_url('i/loading_small')+'" />');
this.container.append(loadingspinner);
this.container.addClass('dndupload-uploading');
},
/**
* Remove progress spinner in the destination node
*/
hide_progress_spinner: function() {
var spinner = this.Y.one('#dndprogresspinner-'+this.clientid);
if (spinner) {
spinner.remove();
}
this.container.removeClass('dndupload-uploading');
},
/**

View File

@ -303,7 +303,7 @@ class MoodleQuickForm_editor extends HTML_QuickForm_element {
$args = new stdClass();
// need these three to filter repositories list
$args->accepted_types = array('image');
$args->return_types = (FILE_INTERNAL | FILE_EXTERNAL);
$args->return_types = (FILE_INTERNAL | FILE_EXTERNAL | FILE_REFERENCE);
$args->context = $ctx;
$args->env = 'filepicker';
// advimage plugin

File diff suppressed because it is too large Load Diff

View File

@ -45,7 +45,10 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element {
public $_helpbutton = '';
/** @var array options provided to initalize filemanager */
protected $_options = array('mainfile'=>'', 'subdirs'=>1, 'maxbytes'=>-1, 'maxfiles'=>-1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL);
// PHP doesn't support 'key' => $value1 | $value2 in class definition
// We cannot do $_options = array('return_types'=> FILE_INTERNAL | FILE_REFERENCE);
// So I have to set null here, and do it in constructor
protected $_options = array('mainfile'=>'', 'subdirs'=>1, 'maxbytes'=>-1, 'maxfiles'=>-1, 'accepted_types'=>'*', 'return_types'=> null);
/**
* Constructor
@ -68,6 +71,9 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element {
if (!empty($options['maxbytes'])) {
$this->_options['maxbytes'] = get_max_upload_file_size($CFG->maxbytes, $options['maxbytes']);
}
if (empty($options['return_types'])) {
$this->_options['return_types'] = (FILE_INTERNAL | FILE_REFERENCE);
}
$this->_type = 'filemanager';
parent::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
}
@ -242,11 +248,13 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element {
$options->subdirs = $this->_options['subdirs'];
$options->target = $id;
$options->accepted_types = $accepted_types;
$options->return_types = FILE_INTERNAL;
$options->return_types = $this->_options['return_types'];
$options->context = $PAGE->context;
$html = $this->_getTabs();
$html .= form_filemanager_render($options);
$fm = new form_filemanager($options);
$output = $PAGE->get_renderer('core', 'files');
$html .= $output->render($fm);
$html .= '<input value="'.$draftitemid.'" name="'.$elname.'" type="hidden" />';
// label element needs 'for' attribute work
@ -266,7 +274,7 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element {
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @todo do not use this abstraction (skodak)
*/
class form_filemanaer_x {
class form_filemanager implements renderable {
/** @var stdClass $options options for filemanager */
public $options;
@ -274,6 +282,18 @@ class form_filemanaer_x {
* Constructor
*
* @param stdClass $options options for filemanager
* default options are:
* maxbytes=>-1,
* maxfiles=>-1,
* itemid=>0,
* subdirs=>false,
* client_id=>uniqid(),
* acepted_types=>'*',
* return_types=>FILE_INTERNAL,
* context=>$PAGE->context,
* author=>fullname($USER),
* licenses=>array build from $CFG->licenses,
* defaultlicense=>$CFG->sitedefaultlicense
*/
public function __construct(stdClass $options) {
global $CFG, $USER, $PAGE;
@ -286,8 +306,22 @@ class form_filemanaer_x {
'client_id'=>uniqid(),
'accepted_types'=>'*',
'return_types'=>FILE_INTERNAL,
'context'=>$PAGE->context
'context'=>$PAGE->context,
'author'=>fullname($USER),
'licenses'=>array()
);
if (!empty($CFG->licenses)) {
$array = explode(',', $CFG->licenses);
foreach ($array as $license) {
$l = new stdClass();
$l->shortname = $license;
$l->fullname = get_string($license, 'license');
$defaults['licenses'][] = $l;
}
}
if (!empty($CFG->sitedefaultlicense)) {
$defaults['defaultlicense'] = $CFG->sitedefaultlicense;
}
foreach ($defaults as $key=>$value) {
if (empty($options->$key)) {
$options->$key = $value;
@ -310,6 +344,18 @@ class form_filemanaer_x {
$this->options->$name = $value;
}
// calculate the maximum file size as minimum from what is specified in filepicker options,
// course options, global configuration and php settings
$coursebytes = $maxbytes = 0;
list($context, $course, $cm) = get_context_info_array($this->options->context->id);
if (is_object($course)) {
$coursebytes = $course->maxbytes;
}
if (!empty($this->options->maxbytes) && $this->options->maxbytes > 0) {
$maxbytes = $this->options->maxbytes;
}
$this->options->maxbytes = get_max_upload_file_size($CFG->maxbytes, $coursebytes, $maxbytes);
// building file picker options
$params = new stdClass();
$params->accepted_types = $options->accepted_types;
@ -320,134 +366,19 @@ class form_filemanaer_x {
$filepicker_options = initialise_filepicker($params);
$this->options->filepicker = $filepicker_options;
}
}
/**
* Print the file manager
*
* <pre>
* $OUTPUT->file_manager($options);
* </pre>
*
* @param array $options associative array with file manager options
* options are:
* maxbytes=>-1,
* maxfiles=>-1,
* itemid=>0,
* subdirs=>false,
* client_id=>uniqid(),
* acepted_types=>'*',
* return_types=>FILE_INTERNAL,
* context=>$PAGE->context
* @return string HTML fragment
*/
function form_filemanager_render($options) {
global $CFG, $OUTPUT, $PAGE;
$fm = new form_filemanaer_x($options); //TODO: this is unnecessary here, the nested options are getting too complex
static $filemanagertemplateloaded;
$html = '';
$options = $fm->options;
$straddfile = get_string('addfile', 'repository');
$strmakedir = get_string('makeafolder', 'moodle');
$strdownload = get_string('downloadfolder', 'repository');
$strloading = get_string('loading', 'repository');
$icon_progress = $OUTPUT->pix_icon('i/loading_small', $strloading).'';
$client_id = $options->client_id;
$itemid = $options->itemid;
list($context, $course, $cm) = get_context_info_array($options->context->id);
if (is_object($course)) {
$course_maxbytes = $course->maxbytes;
} else {
$course_maxbytes = $CFG->maxbytes;
}
if ($options->maxbytes == -1 || empty($options->maxbytes)) {
$options->maxbytes = $CFG->maxbytes;
}
if (empty($options->filecount)) {
$extra = ' style="display:none"';
} else {
$extra = '';
}
$maxbytes = display_size(get_max_upload_file_size($CFG->maxbytes, $course_maxbytes, $options->maxbytes));
if (empty($options->maxfiles) || $options->maxfiles == -1) {
$maxsize = get_string('maxfilesize', 'moodle', $maxbytes);
} else {
$strparam = (object)array('size' => $maxbytes, 'attachments' => $options->maxfiles);
$maxsize = get_string('maxsizeandattachments', 'moodle', $strparam);
}
$strdndenabled = get_string('dndenabled_insentence', 'moodle').$OUTPUT->help_icon('dndenabled');
$loading = get_string('loading', 'repository');
$html .= <<<FMHTML
<div class="filemanager-loading mdl-align" id='filemanager-loading-{$client_id}'>
$icon_progress
</div>
<div id="filemanager-wrapper-{$client_id}" style="display:none">
<div class="fm-breadcrumb" id="fm-path-{$client_id}"></div>
<div class="filemanager-toolbar">
<input type="button" class="fm-btn-add" id="btnadd-{$client_id}" onclick="return false" value="{$straddfile}" />
<input type="button" class="fm-btn-mkdir" id="btncrt-{$client_id}" onclick="return false" value="{$strmakedir}" />
<input type="button" class="fm-btn-download" id="btndwn-{$client_id}" onclick="return false" {$extra} value="{$strdownload}" />
<span> $maxsize </span>
<span id="dndenabled-{$client_id}" style="display: none"> - $strdndenabled </span>
</div>
<div class="filemanager-container" id="filemanager-{$client_id}" style="position: relative" >
<ul id="draftfiles-{$client_id}" class="fm-filelist">
<li>{$loading}</li>
</ul>
</div>
</div>
<div class='clearer'></div>
FMHTML;
if (empty($filemanagertemplateloaded)) {
$filemanagertemplateloaded = true;
$html .= <<<FMHTML
<div id="fm-template" style="display:none">___fullname___ ___action___</div>
FMHTML;
}
$module = array(
'name'=>'form_filemanager',
'fullpath'=>'/lib/form/filemanager.js',
'requires' => array('core_filepicker', 'base', 'io-base', 'node', 'json', 'yui2-button', 'yui2-container', 'yui2-layout', 'yui2-menu', 'yui2-treeview', 'core_dndupload'),
'strings' => array(array('loading', 'repository'), array('nomorefiles', 'repository'), array('confirmdeletefile', 'repository'),
array('add', 'repository'), array('accessiblefilepicker', 'repository'), array('move', 'moodle'),
array('cancel', 'moodle'), array('download', 'moodle'), array('ok', 'moodle'),
array('emptylist', 'repository'), array('nofilesattached', 'repository'), array('entername', 'repository'), array('enternewname', 'repository'),
array('zip', 'editor'), array('unzip', 'moodle'), array('rename', 'moodle'), array('delete', 'moodle'),
array('cannotdeletefile', 'error'), array('confirmdeletefile', 'repository'),
array('nopathselected', 'repository'), array('popupblockeddownload', 'repository'),
array('draftareanofiles', 'repository'), array('path', 'moodle'), array('setmainfile', 'repository'),
array('moving', 'repository'), array('files', 'moodle'), array('serverconnection', 'error')
)
);
$PAGE->requires->js_module($module);
$PAGE->requires->js_init_call('M.form_filemanager.init', array($options), true, $module);
// non javascript file manager
$filemanagerurl = new moodle_url('/repository/draftfiles_manager.php', array(
public function get_nonjsurl() {
global $PAGE;
return new moodle_url('/repository/draftfiles_manager.php', array(
'env'=>'filemanager',
'action'=>'browse',
'itemid'=>$itemid,
'subdirs'=>$options->subdirs,
'maxbytes'=>$options->maxbytes,
'maxfiles'=>$options->maxfiles,
'ctx_id'=>$PAGE->context->id,
'course'=>$PAGE->course->id,
'itemid'=>$this->options->itemid,
'subdirs'=>$this->options->subdirs,
'maxbytes'=>$this->options->maxbytes,
'maxfiles'=>$this->options->maxfiles,
'ctx_id'=>$PAGE->context->id, // TODO ?
'course'=>$PAGE->course->id, // TODO ?
'sesskey'=>sesskey(),
));
$html .= '<noscript>';
$html .= "<div><object type='text/html' data='$filemanagerurl' height='160' width='600' style='border:1px solid #000'></object></div>";
$html .= '</noscript>';
return $html;
}
}

View File

@ -5,8 +5,7 @@ M.form_filepicker.instances = [];
M.form_filepicker.callback = function(params) {
var html = '<a href="'+params['url']+'">'+params['file']+'</a>';
document.getElementById('file_info_'+params['client_id']).innerHTML = html;
M.form_filepicker.add_upload_message(params['client_id']);
M.form_filepicker.Y.one('#file_info_'+params['client_id'] + ' .filepicker-filename').setContent(html);
//When file is added then set status of global variable to true
var elementname = M.core_filepicker.instances[params['client_id']].options.elementname;
M.form_filepicker.instances[elementname].fileadded = true;
@ -14,15 +13,6 @@ M.form_filepicker.callback = function(params) {
M.form_filepicker.Y.one('#id_'+elementname).simulate('change');
};
M.form_filepicker.add_upload_message = function(client_id) {
var div = '<div id="filemanager-uploadmessage'+client_id+'" style="display:none" class="dndupload-target">';
div += M.util.get_string('droptoupload', 'moodle');
div += '</div>';
var iteminfo = document.getElementById('file_info_'+client_id);
iteminfo.innerHTML += div;
iteminfo.style.position = 'relative';
}
/**
* This fucntion is called for each file picker on page.
*/
@ -52,7 +42,6 @@ M.form_filepicker.init = function(Y, options) {
item = document.getElementById('filepicker-wrapper-'+options.client_id);
if (item) {
item.style.display = '';
this.add_upload_message(options.client_id);
}
var dndoptions = {
@ -64,6 +53,7 @@ M.form_filepicker.init = function(Y, options) {
repositories: options.repositories,
formcallback: options.formcallback,
containerprefix: '#file_info_',
containerid: 'file_info_'+options.client_id
};
M.form_dndupload.init(Y, dndoptions);
};

View File

@ -45,7 +45,10 @@ class MoodleQuickForm_filepicker extends HTML_QuickForm_input {
public $_helpbutton = '';
/** @var array options provided to initalize filemanager */
protected $_options = array('maxbytes'=>0, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL);
// PHP doesn't support 'key' => $value1 | $value2 in class definition
// We cannot do $_options = array('return_types'=> FILE_INTERNAL | FILE_REFERENCE);
// So I have to set null here, and do it in constructor
protected $_options = array('maxbytes'=>0, 'accepted_types'=>'*', 'return_types'=>null);
/**
* Constructor
@ -65,6 +68,9 @@ class MoodleQuickForm_filepicker extends HTML_QuickForm_input {
$this->_options[$name] = $value;
}
}
if (!empty($options['return_types'])) {
$this->_options['return_types'] = FILE_INTERNAL | FILE_REFERENCE;
}
if (!empty($options['maxbytes'])) {
$this->_options['maxbytes'] = get_max_upload_file_size($CFG->maxbytes, $options['maxbytes']);
}
@ -137,7 +143,7 @@ class MoodleQuickForm_filepicker extends HTML_QuickForm_input {
$args = new stdClass();
// need these three to filter repositories list
$args->accepted_types = $this->_options['accepted_types']?$this->_options['accepted_types']:'*';
$args->return_types = FILE_INTERNAL;
$args->return_types = FILE_INTERNAL | FILE_REFERENCE;
$args->itemid = $draftitemid;
$args->maxbytes = $this->_options['maxbytes'];
$args->context = $PAGE->context;

View File

@ -136,7 +136,7 @@ abstract class moodleform {
* @param bool $editable
*/
function moodleform($action=null, $customdata=null, $method='post', $target='', $attributes=null, $editable=true) {
global $CFG;
global $CFG, $FULLME;
if (empty($CFG->xmlstrictheaders)) {
// no standard mform in moodle should allow autocomplete with the exception of user signup
// this is valid attribute in html5, sorry, we have to ignore validation errors in legacy xhtml 1.0
@ -152,7 +152,14 @@ abstract class moodleform {
}
if (empty($action)){
$action = strip_querystring(qualified_me());
// do not rely on PAGE->url here because dev often do not setup $actualurl properly in admin_externalpage_setup()
$action = strip_querystring($FULLME);
if (!empty($CFG->sslproxy)) {
// return only https links when using SSL proxy
$action = preg_replace('/^http:/', 'https:', $action, 1);
}
//TODO: use following instead of FULLME - see MDL-33015
//$action = strip_querystring(qualified_me());
}
// Assign custom data first, so that get_form_identifier can use it.
$this->_customdata = $customdata;

View File

@ -2020,6 +2020,7 @@ class core_renderer extends renderer_base {
$straddfile = get_string('openpicker', 'repository');
$strloading = get_string('loading', 'repository');
$strdndenabled = get_string('dndenabled_inbox', 'moodle');
$strdroptoupload = get_string('droptoupload', 'moodle');
$icon_progress = $OUTPUT->pix_icon('i/loading_small', $strloading).'';
$currentfile = $options->currentfile;
@ -2053,8 +2054,9 @@ $icon_progress
EOD;
if ($options->env != 'url') {
$html .= <<<EOD
<div id="file_info_{$client_id}" class="mdl-left filepicker-filelist">
$currentfile<span id="dndenabled-{$client_id}" style="display: none"> - $strdndenabled </span>
<div id="file_info_{$client_id}" class="mdl-left filepicker-filelist" style="position: relative">
<div><span class="filepicker-filename">$currentfile</span><span class="dndupload-message"> - $strdndenabled </span></div>
<div><div class="dndupload-target">{$strdroptoupload}</div></div>
</div>
EOD;
}

View File

@ -428,7 +428,7 @@ class page_requirements_manager {
* @return array description of module or null if not found
*/
protected function find_module($component) {
global $CFG;
global $CFG, $PAGE;
$module = null;
@ -439,25 +439,14 @@ class page_requirements_manager {
case 'core_filepicker':
$module = array('name' => 'core_filepicker',
'fullpath' => '/repository/filepicker.js',
'requires' => array('base', 'node', 'node-event-simulate', 'json', 'async-queue', 'io-base', 'io-upload-iframe', 'io-form', 'yui2-button', 'yui2-container', 'yui2-layout', 'yui2-menu', 'yui2-treeview', 'yui2-dragdrop', 'yui2-cookie'),
'strings' => array(array('add', 'repository'), array('back', 'repository'), array('cancel', 'moodle'), array('close', 'repository'),
array('cleancache', 'repository'), array('copying', 'repository'), array('date', 'repository'), array('downloadsucc', 'repository'),
array('emptylist', 'repository'), array('error', 'repository'), array('federatedsearch', 'repository'),
array('filenotnull', 'repository'), array('getfile', 'repository'), array('help', 'moodle'), array('iconview', 'repository'),
array('invalidjson', 'repository'), array('linkexternal', 'repository'), array('listview', 'repository'),
array('loading', 'repository'), array('login', 'repository'), array('logout', 'repository'), array('noenter', 'repository'),
array('noresult', 'repository'), array('manageurl', 'repository'), array('popup', 'repository'), array('preview', 'repository'),
array('refresh', 'repository'), array('save', 'repository'), array('saveas', 'repository'), array('saved', 'repository'),
array('saving', 'repository'), array('search', 'repository'), array('searching', 'repository'), array('size', 'repository'),
array('submit', 'repository'), array('sync', 'repository'), array('title', 'repository'), array('upload', 'repository'),
array('uploading', 'repository'), array('xhtmlerror', 'repository'),
array('cancel'), array('chooselicense', 'repository'), array('author', 'repository'),array('next', 'moodle'),
array('ok', 'moodle'), array('error', 'moodle'), array('info', 'moodle'), array('norepositoriesavailable', 'repository'), array('norepositoriesexternalavailable', 'repository'),
array('nofilesattached', 'repository'), array('filepicker', 'repository'),
array('nofilesavailable', 'repository'), array('overwrite', 'repository'),
array('renameto', 'repository'), array('fileexists', 'repository'),
'requires' => array('base', 'node', 'node-event-simulate', 'json', 'async-queue', 'io-base', 'io-upload-iframe', 'io-form', 'yui2-treeview', 'panel', 'cookie', 'datatable', 'datatable-sort', 'resize-plugin', 'dd-plugin', 'moodle-core_filepicker'),
'strings' => array(array('lastmodified', 'moodle'), array('name', 'moodle'), array('type', 'repository'), array('size', 'repository'),
array('invalidjson', 'repository'), array('error', 'moodle'), array('info', 'moodle'),
array('nofilesattached', 'repository'), array('filepicker', 'repository'), array('logout', 'repository'),
array('nofilesavailable', 'repository'), array('norepositoriesavailable', 'repository'),
array('fileexistsdialogheader', 'repository'), array('fileexistsdialog_editor', 'repository'),
array('fileexistsdialog_filemanager', 'repository')
array('fileexistsdialog_filemanager', 'repository'), array('renameto', 'repository'),
array('referencesexist', 'repository')
));
break;
case 'core_comment':

View File

@ -198,7 +198,7 @@ class portfolio_format_image extends portfolio_format_file {
* @return string
*/
public static function mimetypes() {
return mimeinfo_from_icon('type', 'image', true);
return file_get_typegroup('type', 'image');
}
/**
@ -286,10 +286,7 @@ class portfolio_format_video extends portfolio_format_file {
* @return array
*/
public static function mimetypes() {
return array_merge(
mimeinfo_from_icon('type', 'video', true),
mimeinfo_from_icon('type', 'avi', true)
);
return file_get_typegroup('type', 'video');
}
}
@ -561,12 +558,7 @@ class portfolio_format_document extends portfolio_format_file {
* @return array of documents mimetypes
*/
public static function mimetypes() {
return array_merge(
array('text/plain', 'text/rtf'),
mimeinfo_from_icon('type', 'word', true),
mimeinfo_from_icon('type', 'docx', true),
mimeinfo_from_icon('type', 'odt', true)
);
return file_get_typegroup('type', 'document');
}
}
@ -588,11 +580,7 @@ class portfolio_format_spreadsheet extends portfolio_format_file {
* @return array of documents mimetypes
*/
public static function mimetypes() {
return array_merge(
mimeinfo_from_icon('type', 'excel', true),
mimeinfo_from_icon('type', 'xlsm', true),
mimeinfo_from_icon('type', 'ods', true)
);
return file_get_typegroup('type', 'spreadsheet');
}
}
@ -614,6 +602,6 @@ class portfolio_format_presentation extends portfolio_format_file {
* @return array presentation document mimetypes
*/
public static function mimetypes() {
return mimeinfo_from_icon('type', 'powerpoint', true);
return file_get_typegroup('type', 'presentation');
}
}

View File

@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->libdir . '/filelib.php');
class filelib_testcase extends basic_testcase {
class filelib_testcase extends advanced_testcase {
public function test_format_postdata_for_curlcall() {
//POST params with just simple types
@ -85,4 +85,188 @@ class filelib_testcase extends basic_testcase {
$contents = download_file_content($testhtml);
$this->assertEquals('47250a973d1b88d9445f94db4ef2c97a', md5($contents));
}
/**
* Testing prepare draft area
*
* @copyright 2012 Dongsheng Cai {@link http://dongsheng.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
public function test_prepare_draft_area() {
global $USER, $DB;
$this->resetAfterTest(true);
$generator = $this->getDataGenerator();
$user = $generator->create_user();
$usercontext = context_user::instance($user->id);
$USER = $DB->get_record('user', array('id'=>$user->id));
$repositorypluginname = 'user';
$args = array();
$args['type'] = $repositorypluginname;
$repos = repository::get_instances($args);
$userrepository = reset($repos);
$this->assertInstanceOf('repository', $userrepository);
$fs = get_file_storage();
$syscontext = context_system::instance();
$component = 'core';
$filearea = 'unittest';
$itemid = 0;
$filepath = '/';
$filename = 'test.txt';
$sourcefield = 'Copyright stuff';
$filerecord = array(
'contextid' => $syscontext->id,
'component' => $component,
'filearea' => $filearea,
'itemid' => $itemid,
'filepath' => $filepath,
'filename' => $filename,
'source' => $sourcefield,
);
$ref = $fs->pack_reference($filerecord);
$originalfile = $fs->create_file_from_string($filerecord, 'Test content');
$fileid = $originalfile->get_id();
$this->assertInstanceOf('stored_file', $originalfile);
// create a user private file
$userfilerecord = new stdClass;
$userfilerecord->contextid = $usercontext->id;
$userfilerecord->component = 'user';
$userfilerecord->filearea = 'private';
$userfilerecord->itemid = 0;
$userfilerecord->filepath = '/';
$userfilerecord->filename = 'userfile.txt';
$userfilerecord->source = 'test';
$userfile = $fs->create_file_from_string($userfilerecord, 'User file content');
$userfileref = $fs->pack_reference($userfilerecord);
$filerefrecord = clone((object)$filerecord);
$filerefrecord->filename = 'testref.txt';
// create a file reference
$fileref = $fs->create_file_from_reference($filerefrecord, $userrepository->id, $userfileref);
$this->assertInstanceOf('stored_file', $fileref);
$this->assertEquals($userrepository->id, $fileref->repository->id);
$this->assertEquals($userfile->get_contenthash(), $fileref->get_contenthash());
$this->assertEquals($userfile->get_filesize(), $fileref->get_filesize());
$this->assertRegExp('#' . $userfile->get_filename(). '$#', $fileref->get_reference_details());
$draftitemid = 0;
file_prepare_draft_area($draftitemid, $syscontext->id, $component, $filearea, $itemid);
$draftfiles = $fs->get_area_files($usercontext->id, 'user', 'draft', $draftitemid);
$this->assertEquals(3, count($draftfiles));
$draftfile = $fs->get_file($usercontext->id, 'user', 'draft', $draftitemid, $filepath, $filename);
$source = unserialize($draftfile->get_source());
$this->assertEquals($ref, $source->original);
$this->assertEquals($sourcefield, $source->source);
$draftfileref = $fs->get_file($usercontext->id, 'user', 'draft', $draftitemid, $filepath, $filerefrecord->filename);
$this->assertInstanceOf('stored_file', $draftfileref);
$this->assertEquals(true, $draftfileref->is_external_file());
// change some information
$author = 'Dongsheng Cai';
$draftfile->set_author($author);
$newsourcefield = 'Get from Flickr';
$license = 'GPLv3';
$draftfile->set_license($license);
// if you want to really just change source field, do this:
$source = unserialize($draftfile->get_source());
$newsourcefield = 'From flickr';
$source->source = $newsourcefield;
$draftfile->set_source(serialize($source));
// Save changed file
file_save_draft_area_files($draftitemid, $syscontext->id, $component, $filearea, $itemid);
$file = $fs->get_file($syscontext->id, $component, $filearea, $itemid, $filepath, $filename);
// Make sure it's the original file id
$this->assertEquals($fileid, $file->get_id());
$this->assertInstanceOf('stored_file', $file);
$this->assertEquals($author, $file->get_author());
$this->assertEquals($license, $file->get_license());
$this->assertEquals($newsourcefield, $file->get_source());
}
/**
* Testing deleting original files
*
* @copyright 2012 Dongsheng Cai {@link http://dongsheng.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
public function test_delete_original_file_from_draft() {
global $USER, $DB;
$this->resetAfterTest(true);
$generator = $this->getDataGenerator();
$user = $generator->create_user();
$usercontext = context_user::instance($user->id);
$USER = $DB->get_record('user', array('id'=>$user->id));
$repositorypluginname = 'user';
$args = array();
$args['type'] = $repositorypluginname;
$repos = repository::get_instances($args);
$userrepository = reset($repos);
$this->assertInstanceOf('repository', $userrepository);
$fs = get_file_storage();
$syscontext = context_system::instance();
$filecontent = 'User file content';
// create a user private file
$userfilerecord = new stdClass;
$userfilerecord->contextid = $usercontext->id;
$userfilerecord->component = 'user';
$userfilerecord->filearea = 'private';
$userfilerecord->itemid = 0;
$userfilerecord->filepath = '/';
$userfilerecord->filename = 'userfile.txt';
$userfilerecord->source = 'test';
$userfile = $fs->create_file_from_string($userfilerecord, $filecontent);
$userfileref = $fs->pack_reference($userfilerecord);
$contenthash = $userfile->get_contenthash();
$filerecord = array(
'contextid' => $syscontext->id,
'component' => 'core',
'filearea' => 'phpunit',
'itemid' => 0,
'filepath' => '/',
'filename' => 'test.txt',
);
// create a file reference
$fileref = $fs->create_file_from_reference($filerecord, $userrepository->id, $userfileref);
$this->assertInstanceOf('stored_file', $fileref);
$this->assertEquals($userrepository->id, $fileref->repository->id);
$this->assertEquals($userfile->get_contenthash(), $fileref->get_contenthash());
$this->assertEquals($userfile->get_filesize(), $fileref->get_filesize());
$this->assertRegExp('#' . $userfile->get_filename(). '$#', $fileref->get_reference_details());
$draftitemid = 0;
file_prepare_draft_area($draftitemid, $usercontext->id, 'user', 'private', 0);
$draftfiles = $fs->get_area_files($usercontext->id, 'user', 'draft', $draftitemid);
$this->assertEquals(2, count($draftfiles));
$draftfile = $fs->get_file($usercontext->id, 'user', 'draft', $draftitemid, $userfilerecord->filepath, $userfilerecord->filename);
$draftfile->delete();
// Save changed file
file_save_draft_area_files($draftitemid, $usercontext->id, 'user', 'private', 0);
// The file reference should be a regular moodle file now
$fileref = $fs->get_file($syscontext->id, 'core', 'phpunit', 0, '/', 'test.txt');
$this->assertEquals(false, $fileref->is_external_file());
$this->assertEquals($contenthash, $fileref->get_contenthash());
$this->assertEquals($filecontent, $fileref->get_content());
}
}

View File

@ -1,57 +0,0 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Unit tests for ../repositorylib.php.
*
* @package core_repository
* @category phpunit
* @author nicolasconnault@gmail.com
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once("$CFG->dirroot/repository/lib.php");
class repositorylib_testcase extends advanced_testcase {
public function test_initialise_filepicker() {
global $PAGE, $SITE;
$this->resetAfterTest(true);
$PAGE->set_url('/');
$PAGE->set_course($SITE);
$this->setAdminUser();
$args = new stdClass();
$args->accepted_types = '*';
$args->return_types = array(FILE_EXTERNAL);
$info = initialise_filepicker($args);
$this->assertInstanceOf('stdClass', $info);
$this->assertObjectHasAttribute('defaultlicense', $info);
$this->assertObjectHasAttribute('licenses', $info);
$this->assertObjectHasAttribute('author', $info);
$this->assertObjectHasAttribute('externallink', $info);
$this->assertObjectHasAttribute('accepted_types', $info);
$this->assertObjectHasAttribute('return_types', $info);
}
}

View File

@ -579,20 +579,19 @@ class mod_assign_renderer extends plugin_renderer_base {
$result = '<ul>';
foreach ($dir['subdirs'] as $subdir) {
$image = $this->output->pix_icon("f/folder", $subdir['dirname'], 'moodle', array('class'=>'icon'));
$image = $this->output->pix_icon(file_folder_icon(), $subdir['dirname'], 'moodle', array('class'=>'icon'));
$result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.s($subdir['dirname']).'</div> '.$this->htmllize_tree($tree, $subdir).'</li>';
}
foreach ($dir['files'] as $file) {
$filename = $file->get_filename();
$icon = mimeinfo("icon", $filename);
if ($CFG->enableplagiarism) {
require_once($CFG->libdir.'/plagiarismlib.php');
$plagiarsmlinks = plagiarism_get_links(array('userid'=>$file->get_userid(), 'file'=>$file, 'cmid'=>$tree->cm->id, 'course'=>$tree->course));
} else {
$plagiarsmlinks = '';
}
$image = $this->output->pix_icon("f/$icon", $filename, 'moodle', array('class'=>'icon'));
$image = $this->output->pix_icon(file_file_icon($file), $filename, 'moodle', array('class'=>'icon'));
$result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.$file->fileurl.' '.$plagiarsmlinks.$file->portfoliobutton.'</div></li>';
}

View File

@ -2118,7 +2118,7 @@ class assignment_base {
$filename = $file->get_filename();
$mimetype = $file->get_mimetype();
$path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/mod_assignment/submission/'.$submission->id.'/'.$filename);
$output .= '<a href="'.$path.'" ><img src="'.$OUTPUT->pix_url(file_mimetype_icon($mimetype)).'" class="icon" alt="'.$mimetype.'" />'.s($filename).'</a>';
$output .= '<a href="'.$path.'" >'.$OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('class' => 'icon')).s($filename).'</a>';
if ($CFG->enableportfolios && $this->portfolio_exportable() && has_capability('mod/assignment:exportownsubmission', $this->context)) {
$button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id, 'submissionid' => $submission->id, 'fileid' => $file->get_id()), '/mod/assignment/locallib.php');
$button->set_format_by_file($file);

View File

@ -59,20 +59,19 @@ class mod_assignment_renderer extends plugin_renderer_base {
$result = '<ul>';
foreach ($dir['subdirs'] as $subdir) {
$image = $this->output->pix_icon("f/folder", $subdir['dirname'], 'moodle', array('class'=>'icon'));
$image = $this->output->pix_icon(file_folder_icon(), $subdir['dirname'], 'moodle', array('class'=>'icon'));
$result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.s($subdir['dirname']).'</div> '.$this->htmllize_tree($tree, $subdir).'</li>';
}
foreach ($dir['files'] as $file) {
$filename = $file->get_filename();
$icon = mimeinfo("icon", $filename);
if ($CFG->enableplagiarism) {
require_once($CFG->libdir.'/plagiarismlib.php');
$plagiarsmlinks = plagiarism_get_links(array('userid'=>$file->get_userid(), 'file'=>$file, 'cmid'=>$tree->cm->id, 'course'=>$tree->course));
} else {
$plagiarsmlinks = '';
}
$image = $this->output->pix_icon("f/$icon", $filename, 'moodle', array('class'=>'icon'));
$image = $this->output->pix_icon(file_file_icon($file), $filename, 'moodle', array('class'=>'icon'));
$result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.$file->fileurl.' '.$plagiarsmlinks.$file->portfoliobutton.'</div></li>';
}

View File

@ -208,7 +208,7 @@ class assignment_online extends assignment_base {
$popup = $OUTPUT->action_link($link, shorten_text(trim(strip_tags(format_text($submission->data1,$submission->data2))), 15), $action, array('title'=>get_string('submission', 'assignment')));
$output = '<div class="files">'.
'<img src="'.$OUTPUT->pix_url('f/html') . '" class="icon" alt="html" />'.
$OUTPUT->pix_icon(file_extension_icon('.htm'), 'html', 'moodle', array('class' => 'icon')).
$popup .
'</div>';
return $output;
@ -233,7 +233,7 @@ class assignment_online extends assignment_base {
$popup = $OUTPUT->action_link($link, get_string('popupinnewwindow','assignment'), $action, array('title'=>get_string('submission', 'assignment')));
$output = '<div class="files">'.
'<img align="middle" src="'.$OUTPUT->pix_url('f/html') . '" height="16" width="16" alt="html" />'.
$OUTPUT->pix_icon(file_extension_icon('.htm'), 'html', 'moodle', array('height' => 16, 'width' => 16)).
$popup .
'</div>';

View File

@ -1123,7 +1123,7 @@ class assignment_upload extends assignment_base {
$filename = $file->get_filename();
$mimetype = $file->get_mimetype();
$link = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/mod_assignment/submission/'.$submission->id.'/'.$filename);
$filenode->add($filename, $link, navigation_node::TYPE_SETTING, null, null, new pix_icon(file_mimetype_icon($mimetype),''));
$filenode->add($filename, $link, navigation_node::TYPE_SETTING, null, null, new pix_icon(file_file_icon($file),''));
}
}
}

View File

@ -42,7 +42,7 @@ class assignment_uploadsingle extends assignment_base {
$found = true;
$mimetype = $file->get_mimetype();
$path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/mod_assignment/submission/'.$submission->id.'/'.$filename);
$output .= '<a href="'.$path.'" ><img class="icon" src="'.$OUTPUT->pix_url(file_mimetype_icon($mimetype)).'" alt="'.$mimetype.'" />'.s($filename).'</a><br />';
$output .= '<a href="'.$path.'" >'.$OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('class' => 'icon')).s($filename).'</a><br />';
$output .= plagiarism_get_links(array('userid'=>$userid, 'file'=>$file, 'cmid'=>$this->cm->id, 'course'=>$this->course, 'assignment'=>$this->assignment));
$output .='<br/>';
}
@ -370,7 +370,7 @@ class assignment_uploadsingle extends assignment_base {
$filename = $file->get_filename();
$mimetype = $file->get_mimetype();
$link = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/mod_assignment', 'submission/'.$submission->id.'/'.$filename);
$filenode->add($filename, $link, navigation_node::TYPE_SETTING, null, null, new pix_icon(file_mimetype_icon($mimetype), ''));
$filenode->add($filename, $link, navigation_node::TYPE_SETTING, null, null, new pix_icon(file_file_icon($file), ''));
}
}
}

View File

@ -50,7 +50,7 @@ class data_field_file extends data_field_base {
if (empty($content->content1)) {
// Print icon if file already exists
$src = moodle_url::make_draftfile_url($itemid, '/', $file->get_filename());
$displayname = '<img src="'.$OUTPUT->pix_url(file_mimetype_icon($file->get_mimetype())).'" class="icon" alt="'.$file->get_mimetype().'" />'. '<a href="'.$src.'" >'.s($file->get_filename()).'</a>';
$displayname = $OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('class' => 'icon')). '<a href="'.$src.'" >'.s($file->get_filename()).'</a>';
} else {
$displayname = 'no file added';
@ -142,7 +142,7 @@ class data_field_file extends data_field_base {
$width = $this->field->param1 ? ' width = "'.s($this->field->param1).'" ':' ';
$height = $this->field->param2 ? ' height = "'.s($this->field->param2).'" ':' ';
$str = '<img src="'.$OUTPUT->pix_url(file_mimetype_icon($file->get_mimetype())).'" height="16" width="16" alt="'.$file->get_mimetype().'" />&nbsp;'.
$str = $OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('width' => 16, 'height' => 16)). '&nbsp;'.
'<a href="'.$src.'" >'.s($name).'</a>';
return $str;
}

View File

@ -52,7 +52,7 @@ class data_field_picture extends data_field_base {
if (empty($content->content1)) {
// Print icon if file already exists
$src = moodle_url::make_draftfile_url($itemid, '/', $file->get_filename());
$displayname = '<img src="'.$OUTPUT->pix_url(file_mimetype_icon($file->get_mimetype())).'" class="icon" alt="'.$file->get_mimetype().'" />'. '<a href="'.$src.'" >'.s($file->get_filename()).'</a>';
$displayname = $OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('class' => 'icon')). '<a href="'.$src.'" >'.s($file->get_filename()).'</a>';
} else {
$displayname = get_string('nofilesattached', 'repository');

View File

@ -48,7 +48,7 @@ $PAGE->set_activity_record($folder);
$data = new stdClass();
$data->id = $cm->id;
$options = array('mainfile'=>true, 'subdirs'=>1, 'maxbytes'=>$CFG->maxbytes, 'maxfiles'=>-1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL);
$options = array('mainfile'=>true, 'subdirs'=>1, 'maxbytes'=>$CFG->maxbytes, 'maxfiles'=>-1, 'accepted_types'=>'*');
file_prepare_standard_filemanager($data, 'files', $options, $context, 'mod_folder', 'content', 0);
$mform = new mod_folder_edit_form(null, array('data'=>$data, 'options'=>$options));

View File

@ -48,7 +48,7 @@ class mod_folder_mod_form extends moodleform_mod {
//-------------------------------------------------------
$mform->addElement('header', 'content', get_string('contentheader', 'folder'));
$mform->addElement('filemanager', 'files', get_string('files'), null, array('subdirs'=>1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL));
$mform->addElement('filemanager', 'files', get_string('files'), null, array('subdirs'=>1, 'accepted_types'=>'*'));
//-------------------------------------------------------
$this->standard_coursemodule_elements();

View File

@ -3911,7 +3911,7 @@ function forum_print_attachments($post, $cm, $type) {
foreach ($files as $file) {
$filename = $file->get_filename();
$mimetype = $file->get_mimetype();
$iconimage = '<img src="'.$OUTPUT->pix_url(file_mimetype_icon($mimetype)).'" class="icon" alt="'.$mimetype.'" />';
$iconimage = $OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('class' => 'icon'));
$path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$context->id.'/mod_forum/attachment/'.$post->id.'/'.$filename);
if ($type == 'html') {

View File

@ -1553,7 +1553,7 @@ function glossary_print_attachments($entry, $cm, $type=NULL, $align="left") {
foreach ($files as $file) {
$filename = $file->get_filename();
$mimetype = $file->get_mimetype();
$iconimage = '<img src="'.$OUTPUT->pix_url(file_mimetype_icon($mimetype)).'" class="icon" alt="'.$mimetype.'" />';
$iconimage = $OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('class' => 'icon'));
$path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$context->id.'/mod_glossary/attachment/'.$entry->id.'/'.$filename);
if ($type == 'html') {

View File

@ -256,7 +256,7 @@ function resource_get_coursemodule_info($coursemodule) {
$files = $fs->get_area_files($context->id, 'mod_resource', 'content', 0, 'sortorder DESC, id ASC', false); // TODO: this is not very efficient!!
if (count($files) >= 1) {
$mainfile = reset($files);
$info->icon = file_extension_icon($mainfile->get_filename());
$info->icon = file_file_icon($mainfile);
$resource->mainfile = $mainfile->get_filename();
}

View File

@ -303,14 +303,13 @@ function resource_get_optional_details($resource, $cm) {
// For a typical file resource, the sortorder is 1 for the main file
// and 0 for all other files. This sort approach is used just in case
// there are situations where the file has a different sort order
$mimetype = $DB->get_field_sql(
'SELECT mimetype FROM {files} WHERE contextid=? ORDER BY sortorder DESC',
$record = $DB->get_record_sql(
'SELECT filename, mimetype FROM {files} WHERE contextid=? ORDER BY sortorder DESC',
array($context->id), IGNORE_MULTIPLE);
// Only show type if it is not unknown
if ($mimetype && $mimetype !== 'document/unknown') {
$type = get_mimetype_description($mimetype);
// There are some known mimetypes which don't have descriptions
if ($type === get_string('document/unknown','mimetypes')) {
if ($record) {
$type = get_mimetype_description($record);
if ($type === get_mimetype_description('document/unknown')) {
$type = '';
}
}

View File

@ -61,9 +61,9 @@ class mod_resource_mod_form extends moodleform_mod {
$mform->addElement('header', 'contentsection', get_string('contentheader', 'resource'));
$filemanager_options = array();
// 3 == FILE_EXTERNAL & FILE_INTERNAL
// 3 == FILE_EXTERNAL | FILE_INTERNAL | FILE_REFERENCE
// These two constant names are defined in repository/lib.php
$filemanager_options['return_types'] = 3;
$filemanager_options['return_types'] = 7;
$filemanager_options['accepted_types'] = '*';
$filemanager_options['maxbytes'] = 0;
$filemanager_options['maxfiles'] = -1;

View File

@ -549,14 +549,13 @@ function url_guess_icon($fullurl) {
if (substr_count($fullurl, '/') < 3 or substr($fullurl, -1) === '/') {
// most probably default directory - index.php, index.html, etc.
return 'f/web';
return file_extension_icon('.htm');
}
$icon = mimeinfo('icon', $fullurl);
$icon = 'f/'.str_replace(array('.gif', '.png'), '', $icon);
$icon = file_extension_icon($fullurl);
if ($icon === 'f/html' or $icon === 'f/unknown') {
$icon = 'f/web';
if ($icon === file_extension_icon('')) {
return file_extension_icon('.htm');
}
return $icon;

View File

@ -67,8 +67,7 @@ class mod_wiki_edit_form extends moodleform {
$fieldname = get_string('format' . $format, 'wiki');
if ($format != 'html') {
// Use wiki editor
$ft = new filetype_parser;
$extensions = $ft->get_extensions('image');
$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();

View File

@ -105,18 +105,18 @@ class MoodleQuickForm_wikifiletable extends HTML_QuickForm_element {
$checkbox .= " />";
//actions
$icon = mimeinfo_from_type('icon', $file->get_mimetype());
$icon = file_file_icon($file);
$file_url = file_encode_url($CFG->wwwroot.'/pluginfile.php', "/{$this->_contextid}/mod_wiki/attachments/{$this->_fileareaitemid}/".$file->get_filename());
$action_icons = "";
if(!empty($tags['attach'])) {
$action_icons .= "<a href=\"javascript:void(0)\" class=\"wiki-attachment-attach\" ".$this->printInsertTags($tags['attach'], $file->get_filename())." title=\"".get_string('attachmentattach', 'wiki')."\"><img src=\"".$OUTPUT->pix_url('f/pdf')->out()."\" alt=\"Attach\" /></a>"; //TODO: localize
$action_icons .= "<a href=\"javascript:void(0)\" class=\"wiki-attachment-attach\" ".$this->printInsertTags($tags['attach'], $file->get_filename())." title=\"".get_string('attachmentattach', 'wiki')."\">".$OUTPUT->pix_icon($icon, "Attach")."</a>"; //TODO: localize
}
$action_icons .= "&nbsp;&nbsp;<a href=\"javascript:void(0)\" class=\"wiki-attachment-link\" ".$this->printInsertTags($tags['link'], $file_url)." title=\"".get_string('attachmentlink', 'wiki')."\"><img src=\"".$OUTPUT->pix_url('f/web')->out()."\" alt=\"Link\" /></a>";
$action_icons .= "&nbsp;&nbsp;<a href=\"javascript:void(0)\" class=\"wiki-attachment-link\" ".$this->printInsertTags($tags['link'], $file_url)." title=\"".get_string('attachmentlink', 'wiki')."\">".$OUTPUT->pix_icon($icon, "Link")."</a>";
if ($icon == 'image') {
$action_icons .= "&nbsp;&nbsp;<a href=\"javascript:void(0)\" class=\"wiki-attachment-image\" ".$this->printInsertTags($tags['image'], $file->get_filename())." title=\"".get_string('attachmentimage', 'wiki')."\"><img src=\"".$OUTPUT->pix_url('f/image')->out()."\" alt=\"Image\" /></a>"; //TODO: localize
if (file_mimetype_in_typegroup($file->get_mimetype(), 'web_image')) {
$action_icons .= "&nbsp;&nbsp;<a href=\"javascript:void(0)\" class=\"wiki-attachment-image\" ".$this->printInsertTags($tags['image'], $file->get_filename())." title=\"".get_string('attachmentimage', 'wiki')."\">".$OUTPUT->pix_icon($icon, "Image")."</a>"; //TODO: localize
}
$htmltable->data[] = array($checkbox, '<a href="'.$file_url.'">'.$file->get_filename().'</a>', $action_icons);

View File

@ -78,7 +78,7 @@ $data = new stdClass();
$data->returnurl = $returnurl;
$data->subwikiid = $subwiki->id;
$maxbytes = get_max_upload_file_size($CFG->maxbytes, $COURSE->maxbytes);
$options = array('subdirs'=>0, 'maxbytes'=>$maxbytes, 'maxfiles'=>-1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL);
$options = array('subdirs'=>0, 'maxbytes'=>$maxbytes, 'maxfiles'=>-1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL | FILE_REFERENCE);
file_prepare_standard_filemanager($data, 'files', $options, $context, 'mod_wiki', 'attachments', $subwiki->id);
$mform = new mod_wiki_filesedit_form(null, array('data'=>$data, 'options'=>$options));

View File

@ -526,14 +526,13 @@ class mod_wiki_renderer extends plugin_renderer_base {
}
$result = '<ul>';
foreach ($dir['subdirs'] as $subdir) {
$image = $this->output->pix_icon("f/folder", $subdir['dirname'], 'moodle', array('class'=>'icon'));
$image = $this->output->pix_icon(file_folder_icon(), $subdir['dirname'], 'moodle', array('class'=>'icon'));
$result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.s($subdir['dirname']).'</div> '.$this->htmllize_tree($tree, $subdir).'</li>';
}
foreach ($dir['files'] as $file) {
$url = file_encode_url("$CFG->wwwroot/pluginfile.php", '/'.$tree->context->id.'/mod_wiki/attachments/' . $tree->subwiki->id . '/'. $file->get_filepath() . $file->get_filename(), true);
$filename = $file->get_filename();
$icon = mimeinfo("icon", $filename);
$image = $this->output->pix_icon("f/$icon", $filename, 'moodle', array('class'=>'icon'));
$image = $this->output->pix_icon(file_file_icon($file), $filename, 'moodle', array('class'=>'icon'));
$result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.html_writer::link($url, $filename).'</div></li>';
}
$result .= '</ul>';

View File

@ -749,14 +749,13 @@ class mod_workshop_renderer extends plugin_renderer_base {
$fileurl = file_encode_url($CFG->wwwroot . '/pluginfile.php',
'/' . $ctx->id . '/mod_workshop/submission_attachment/' . $submissionid . $filepath . $filename, true);
$type = $file->get_mimetype();
$type = mimeinfo_from_type('type', $type);
$image = html_writer::empty_tag('img', array('src'=>$this->output->pix_url(file_mimetype_icon($type)), 'alt'=>$type, 'class'=>'icon'));
$image = $this->output->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('class' => 'icon'));
$linkhtml = html_writer::link($fileurl, $image) . substr($filepath, 1) . html_writer::link($fileurl, $filename);
$linktxt = "$filename [$fileurl]";
if ($format == 'html') {
if (in_array($type, array('image/gif', 'image/jpeg', 'image/png'))) {
if (file_mimetype_in_typegroup($type, 'web_image')) {
$preview = html_writer::empty_tag('img', array('src' => $fileurl, 'alt' => '', 'class' => 'preview'));
$preview = html_writer::tag('a', $preview, array('href' => $fileurl));
$outputimgs .= $this->output->container($preview);

View File

@ -147,7 +147,7 @@ if ($edit) {
'context' => $workshop->context
);
$attachmentopts = array('subdirs' => true, 'maxfiles' => $maxfiles, 'maxbytes' => $maxbytes);
$attachmentopts = array('subdirs' => true, 'maxfiles' => $maxfiles, 'maxbytes' => $maxbytes, 'return_types' => FILE_INTERNAL);
$submission = file_prepare_standard_editor($submission, 'content', $contentopts, $workshop->context,
'mod_workshop', 'submission_content', $submission->id);
$submission = file_prepare_standard_filemanager($submission, 'attachment', $attachmentopts, $workshop->context,

BIN
pix/a/add_file.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
pix/a/create_folder.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
pix/a/download_all.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -0,0 +1,15 @@
FileTypesIcons Copyright 2012 Renato Veras
These icons are free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

15
pix/f/Oxygen-LICENSE.txt Normal file
View File

@ -0,0 +1,15 @@
FileTypesIcons Copyright 2012 Oxygen Team
These icons are free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

BIN
pix/f/audio-128.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
pix/f/audio-24.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

BIN
pix/f/audio-256.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

BIN
pix/f/audio-48.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

BIN
pix/f/audio-64.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

BIN
pix/f/audio-72.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

BIN
pix/f/audio-80.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

BIN
pix/f/audio-96.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 182 B

BIN
pix/f/audio.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

BIN
pix/f/avi-128.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
pix/f/avi-24.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
pix/f/avi-256.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

BIN
pix/f/avi-32.png Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

BIN
pix/f/avi-48.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

BIN
pix/f/avi-64.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

BIN
pix/f/avi-72.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

BIN
pix/f/avi-80.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

BIN
pix/f/avi-96.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 122 B

BIN
pix/f/avi.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 927 B

Some files were not shown because too many files have changed in this diff Show More