Skip to content

Commit

Permalink
Merge branch 'MDL-32639-24' of git://github.com/FMCorz/moodle into MO…
Browse files Browse the repository at this point in the history
…ODLE_24_STABLE
  • Loading branch information
danpoltawski committed Jan 8, 2013
2 parents f923f7a + 45cff73 commit 2e25f80
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 24 deletions.
10 changes: 6 additions & 4 deletions lib/filestorage/zip_archive.php
Expand Up @@ -361,18 +361,20 @@ public function add_directory($localname) {
if (!isset($this->za)) {
return false;
}
$localname = ltrim($localname, '/'). '/';
$localname = trim($localname, '/'). '/';
$localname = $this->mangle_pathname($localname);

if ($localname === '/') {
//sorry - conversion failed badly
return false;
}

if (!$this->za->addEmptyDir($localname)) {
return false;
if ($localname !== '') {
if (!$this->za->addEmptyDir($localname)) {
return false;
}
$this->modified = true;
}
$this->modified = true;
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/form/filemanager.js
Expand Up @@ -220,9 +220,9 @@ M.form_filemanager.init = function(Y, options) {
params: {'filepath':filepath},
callback: function(id, obj, args) {
scope.filecount = obj.filecount;
scope.check_buttons();
scope.options = obj;
scope.lazyloading = {};
scope.check_buttons();
scope.render(obj);
}
}, true);
Expand Down
15 changes: 9 additions & 6 deletions repository/draftfiles_ajax.php
Expand Up @@ -220,7 +220,11 @@

$parent_path = $file->get_parent_directory()->get_filepath();

if ($newfile = $zipper->archive_to_storage(array($file), $user_context->id, 'user', 'draft', $draftid, $parent_path, $filepath.'.zip', $USER->id)) {
$filepath = explode('/', trim($file->get_filepath(), '/'));
$filepath = array_pop($filepath);
$zipfile = repository::get_unused_filename($draftid, $parent_path, $filepath . '.zip');

if ($newfile = $zipper->archive_to_storage(array($filepath => $file), $user_context->id, 'user', 'draft', $draftid, $parent_path, $zipfile, $USER->id)) {
$return = new stdClass();
$return->filepath = $parent_path;
echo json_encode($return);
Expand All @@ -242,19 +246,18 @@

$stored_file = $fs->get_file($user_context->id, 'user', 'draft', $draftid, $filepath, '.');
if ($filepath === '/') {
$parent_path = '/';
$filename = get_string('files').'.zip';
} else {
$parent_path = $stored_file->get_parent_directory()->get_filepath();
$filename = trim($filepath, '/').'.zip';
$filename = explode('/', trim($filepath, '/'));
$filename = array_pop($filename) . '.zip';
}

// archive compressed file to an unused draft area
$newdraftitemid = file_get_unused_draft_itemid();
if ($newfile = $zipper->archive_to_storage(array($stored_file), $user_context->id, 'user', 'draft', $newdraftitemid, '/', $filename, $USER->id)) {
if ($newfile = $zipper->archive_to_storage(array('/' => $stored_file), $user_context->id, 'user', 'draft', $newdraftitemid, '/', $filename, $USER->id)) {
$return = new stdClass();
$return->fileurl = moodle_url::make_draftfile_url($newdraftitemid, '/', $filename)->out();
$return->filepath = $parent_path;
$return->filepath = $filepath;
echo json_encode($return);
} else {
echo json_encode(false);
Expand Down
31 changes: 18 additions & 13 deletions repository/draftfiles_manager.php
Expand Up @@ -139,17 +139,17 @@
$zipper = new zip_packer();

$file = $fs->get_file($user_context->id, 'user', 'draft', $itemid, $draftpath, '.');
if ($file->get_parent_directory()) {
$parent_path = $file->get_parent_directory()->get_filepath();
$filename = trim($draftpath, '/').'.zip';
} else {
$parent_path = '/';
if ($draftpath === '/') {
$filename = get_string('files').'.zip';
} else {
$filename = explode('/', trim($draftpath, '/'));
$filename = array_pop($filename) . '.zip';
}

if ($newfile = $zipper->archive_to_storage(array($file), $user_context->id, 'user', 'draft', $itemid, $parent_path, $filename, $USER->id)) {
$fileurl = moodle_url::make_draftfile_url($itemid, '/', $filename)->out();
header('Location: ' . $fileurl );
$newdraftitemid = file_get_unused_draft_itemid();
if ($newfile = $zipper->archive_to_storage(array('/' => $file), $user_context->id, 'user', 'draft', $newdraftitemid, '/', $filename, $USER->id)) {
$fileurl = moodle_url::make_draftfile_url($newdraftitemid, '/', $filename)->out();
header('Location: ' . $fileurl);
} else {
print_error('cannotdownloaddir', 'repository');
}
Expand All @@ -161,14 +161,17 @@
$file = $fs->get_file($user_context->id, 'user', 'draft', $itemid, $draftpath, '.');
if (!$file->get_parent_directory()) {
$parent_path = '/';
$filepath = '/';
$filename = get_string('files').'.zip';
} else {
$parent_path = $file->get_parent_directory()->get_filepath();
$filepath = explode('/', trim($file->get_filepath(), '/'));
$filename = array_pop($filepath).'.zip';
$filepath = array_pop($filepath);
$filename = $filepath.'.zip';
}

$newfile = $zipper->archive_to_storage(array($file), $user_context->id, 'user', 'draft', $itemid, $parent_path, $filename, $USER->id);
$filename = repository::get_unused_filename($itemid, $parent_path, $filename);
$newfile = $zipper->archive_to_storage(array($filepath => $file), $user_context->id, 'user', 'draft', $itemid, $parent_path, $filename, $USER->id);

$home_url->param('action', 'browse');
$home_url->param('draftpath', $parent_path);
Expand Down Expand Up @@ -269,7 +272,7 @@
$path = '/' . trim($draftpath, '/') . '/';
$parts = explode('/', $path);
foreach ($parts as $part) {
if (!empty($part)) {
if ($part != '') {
$trail .= ('/'.$part.'/');
$data->path[] = array('name'=>$part, 'path'=>$trail);
$home_url->param('draftpath', $trail);
Expand All @@ -295,8 +298,10 @@
$home_url->param('action', 'mkdirform');
echo ' <a href="'.$home_url->out().'">'.get_string('makeafolder', 'moodle').'</a>';
}
$home_url->param('action', 'downloaddir');
echo html_writer::link($home_url, get_string('downloadfolder', 'repository'), array('target'=>'_blank'));
if (!empty($files->list)) {
$home_url->param('action', 'downloaddir');
echo ' ' . html_writer::link($home_url, get_string('downloadfolder', 'repository'), array('target'=>'_blank'));
}
}
echo '</div>';

Expand Down
1 change: 1 addition & 0 deletions theme/base/style/filemanager.css
Expand Up @@ -268,6 +268,7 @@ a.ygtvspacer:hover {color: transparent;text-decoration: none;}
.filemanager.fm-loaded .filemanager-loading {display:none;}
.filemanager.fm-maxfiles .fp-btn-add {display:none;}
.filemanager.fm-maxfiles .dndupload-message {display:none;}
.filemanager.fm-noitems .fp-btn-download,
.filemanager.fm-nofiles .fp-btn-download {display:none;}
.filemanager .fm-empty-container {display:none;}
.filemanager.fm-noitems .filemanager-container .fp-content {display:none;}
Expand Down

0 comments on commit 2e25f80

Please sign in to comment.