Skip to content

Commit

Permalink
1. Directory Resources now support sub directories
Browse files Browse the repository at this point in the history
2.  Subdirectories in File Manager now display their total size
  • Loading branch information
moodler committed May 16, 2004

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent d5aacf3 commit 16a5602
Showing 6 changed files with 103 additions and 27 deletions.
3 changes: 2 additions & 1 deletion files/index.php
Original file line number Diff line number Diff line change
@@ -715,13 +715,14 @@ function displaydir ($wdir) {
$filename = $fullpath."/".$dir;
$fileurl = rawurlencode($wdir."/".$dir);
$filesafe = rawurlencode($dir);
$filesize = display_size(get_directory_size("$fullpath/$dir"));
$filedate = userdate(filemtime($filename), "%d %b %Y, %I:%M %p");

echo "<TR>";

print_cell("center", "<INPUT TYPE=checkbox NAME=\"file$count\" VALUE=\"$fileurl\">");
print_cell("left", "<A HREF=\"index.php?id=$id&wdir=$fileurl\"><IMG SRC=\"$CFG->pixpath/f/folder.gif\" HEIGHT=16 WIDTH=16 BORDER=0 ALT=\"Folder\"></A> <A HREF=\"index.php?id=$id&wdir=$fileurl\">".htmlspecialchars($dir)."</A>");
print_cell("right", "-");
print_cell("right", "<b>$filesize</b>");
print_cell("right", $filedate);
print_cell("right", "<A HREF=\"index.php?id=$id&wdir=$wdir&file=$filesafe&action=rename\">$strrename</A>");

50 changes: 43 additions & 7 deletions lib/moodlelib.php
Original file line number Diff line number Diff line change
@@ -1526,19 +1526,25 @@ function get_max_upload_sizes($sitebytes=0, $coursebytes=0, $modulebytes=0) {
return $filesize;
}

function get_directory_list($rootdir, $excludefile="", $descend=true, $justdirs=false) {
function get_directory_list($rootdir, $excludefile="", $descend=true, $getdirs=false, $getfiles=true) {
/// Returns an array with all the filenames in
/// all subdirectories, relative to the given rootdir.
/// If excludefile is defined, then that file/directory is ignored
/// If justdirs is defined, then only subdirectories are listed, otherwise just files
/// If getdirs is true, then (sub)directories are included in the output
/// If getfiles is true, then files are included in the output
/// (at least one of these must be true!)

$dirs = array();

if (!is_dir($rootdir)) {
if (!$getdirs and !$getfiles) { // Nothing to show
return $dirs;
}

if (!$dir = opendir($rootdir)) {
if (!is_dir($rootdir)) { // Must be a directory
return $dirs;
}

if (!$dir = opendir($rootdir)) { // Can't open it for some reason
return $dirs;
}

@@ -1549,16 +1555,16 @@ function get_directory_list($rootdir, $excludefile="", $descend=true, $justdirs=
}
$fullfile = "$rootdir/$file";
if (filetype($fullfile) == "dir") {
if ($justdirs) {
if ($getdirs) {
$dirs[] = $file;
}
if ($descend) {
$subdirs = get_directory_list($fullfile, $excludefile, $descend, $justdirs);
$subdirs = get_directory_list($fullfile, $excludefile, $descend, $getdirs, $getfiles);
foreach ($subdirs as $subdir) {
$dirs[] = "$file/$subdir";
}
}
} else if (!$justdirs) {
} else if ($getfiles) {
$dirs[] = $file;
}
}
@@ -1569,6 +1575,36 @@ function get_directory_list($rootdir, $excludefile="", $descend=true, $justdirs=
return $dirs;
}

function get_directory_size($rootdir, $excludefile="") {
/// Adds up all the files in a directory and works out the size

$size = 0;

if (!is_dir($rootdir)) { // Must be a directory
return $dirs;
}

if (!$dir = opendir($rootdir)) { // Can't open it for some reason
return $dirs;
}

while (false !== ($file = readdir($dir))) {
$firstchar = substr($file, 0, 1);
if ($firstchar == "." or $file == "CVS" or $file == $excludefile) {
continue;
}
$fullfile = "$rootdir/$file";
if (filetype($fullfile) == "dir") {
$size += get_directory_size($fullfile, $excludefile);
} else {
$size += filesize($fullfile);
}
}
closedir($dir);

return $size;
}

function get_real_size($size=0) {
/// Converts numbers like 10M into bytes
if (!$size) {
2 changes: 1 addition & 1 deletion mod/resource/details.php
Original file line number Diff line number Diff line change
@@ -399,7 +399,7 @@
break;

case DIRECTORY:
$rawdirs = get_directory_list("$CFG->dataroot/$course->id", 'moddata', true, true);
$rawdirs = get_directory_list("$CFG->dataroot/$course->id", 'moddata', true, true, false);
$dirs = array();
foreach ($rawdirs as $rawdir) {
$dirs[$rawdir] = $rawdir;
2 changes: 1 addition & 1 deletion mod/resource/version.php
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
////////////////////////////////////////////////////////////////////////////////

$module->version = 2004013101;
$module->requires = 2004050200; // Requires this Moodle version
$module->requires = 2004051600; // Requires this Moodle version
$module->cron = 0;

?>
71 changes: 55 additions & 16 deletions mod/resource/view.php
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@

require_variable($id); // Course Module ID
optional_variable($frameset, "");
optional_variable($subdir, "");

if (!empty($CFG->forcelogin)) {
require_login();
@@ -419,8 +420,41 @@
require_once("../../files/mimetypes.php");

add_to_log($course->id, "resource", "view", "view.php?id=$cm->id", $resource->id, $cm->id);
print_header($pagetitle, "$course->fullname", "$navigation $resource->name",
"", "", true, update_module_button($cm->id, $course->id, $strresource), navmenu($course, $cm));

if ($resource->reference) {
$relativepath = "$course->id/$resource->reference";
} else {
$relativepath = "$course->id";
}

if ($subdir) {
if (detect_munged_arguments($subdir)) {
error("The value for 'subdir' contains illegal characters!");
}
$relativepath = "$relativepath$subdir";

$subs = explode('/', $subdir);
array_shift($subs);
$countsubs = count($subs);
$count = 0;
$subnav = "<a href=\"view.php?id=$cm->id\">$resource->name</a>";
$backsub = '';
foreach ($subs as $sub) {
$count++;
if ($count < $countsubs) {
$backsub .= "/$sub";
$subnav .= " -> <a href=\"view.php?id=$cm->id&subdir=$backsub\">$sub</a>";
} else {
$subnav .= " -> $sub";
}
}
} else {
$subnav = $resource->name;
}

print_header($pagetitle, "$course->fullname", "$navigation $subnav",
"", "", true, update_module_button($cm->id, $course->id, $strresource),
navmenu($course, $cm));

if (trim($resource->summary)) {
print_simple_box(text_to_html($resource->summary), "center");
@@ -429,13 +463,7 @@

print_simple_box_start("center", "", "$THEME->cellcontent", '0' );

if ($resource->reference) {
$relativepath = "$course->id/$resource->reference";
} else {
$relativepath = "$course->id";
}

$files = get_directory_list("$CFG->dataroot/$relativepath", 'moddata', false);
$files = get_directory_list("$CFG->dataroot/$relativepath", 'moddata', false, true, true);
$strftime = get_string('strftimedatetime');
$strname = get_string("name");
$strsize = get_string("size");
@@ -447,28 +475,39 @@
"<th align=\"right\">$strmodified</th>".
"</tr>";
foreach ($files as $file) {
$icon = mimeinfo("icon", $file);
if (is_dir("$CFG->dataroot/$relativepath/$file")) { // Must be a directory
$icon = "folder.gif";
$relativeurl = "/view.php?blah";
$filesize = display_size(get_directory_size("$CFG->dataroot/$relativepath/$file"));

if ($CFG->slasharguments) {
$relativeurl = "/file.php/$relativepath/$file";
} else {
$relativeurl = "/file.php?file=/$relativepath/$file";
$icon = mimeinfo("icon", $file);

if ($CFG->slasharguments) {
$relativeurl = "/file.php/$relativepath/$file";
} else {
$relativeurl = "/file.php?file=/$relativepath/$file";
}
$filesize = display_size(filesize("$CFG->dataroot/$relativepath/$file"));
}
$filesize = display_size(filesize("$CFG->dataroot/$course->id/$resource->reference/$file"));

echo '<tr>';
echo '<td>';
echo "<img src=\"$CFG->pixpath/f/$icon\" width=\"16\" height=\"16\">";
echo '</td>';
echo '<td nowrap="nowrap"><p>';
link_to_popup_window($relativeurl, "resourceedirectory$resource->id", "$file", 450, 600, '');
if ($icon == 'folder.gif') {
echo "<a href=\"view.php?id=$cm->id&subdir=$subdir/$file\">$file</a>";
} else {
link_to_popup_window($relativeurl, "resourceedirectory$resource->id", "$file", 450, 600, '');
}
echo '</p></td>';
echo '<td>&nbsp;</td>';
echo '<td align="right" nowrap="nowrap"><p><font size="-1">';
echo $filesize;
echo '</font></p></td>';
echo '<td align="right" nowrap="nowrap"><p><font size="-1">';
echo userdate(filectime("$CFG->dataroot/$course->id/$resource->reference/$file"), $strftime);
echo userdate(filectime("$CFG->dataroot/$relativepath/$file"), $strftime);
echo '</font></p></td>';
echo '</tr>';
}
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
// database to determine whether upgrades should
// be performed (see lib/db/*.php)

$version = 2004051500; // The current version is a date (YYYYMMDDXX)
$version = 2004051600; // The current version is a date (YYYYMMDDXX)

$release = "1.3 Beta +"; // User-friendly version number

0 comments on commit 16a5602

Please sign in to comment.