Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
backupdata folder is no longer displayed in list of directories when …
…setting up Directory Resource - partially related to MDL-6280 ; and some other typo fixes; get_directory_list() no accepts also array of exluded files
  • Loading branch information
skodak committed Sep 17, 2006
1 parent 746a04c commit 7f5bc80
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
10 changes: 7 additions & 3 deletions lib/moodlelib.php
Expand Up @@ -3781,7 +3781,7 @@ function check_potential_filename($destination,$filename,$files) {
* all subdirectories, relative to the given rootdir
* @todo Finish documenting this function. Add examples of $excludefile usage.
*/
function get_directory_list($rootdir, $excludefile='', $descend=true, $getdirs=false, $getfiles=true) {
function get_directory_list($rootdir, $excludefiles='', $descend=true, $getdirs=false, $getfiles=true) {

$dirs = array();

Expand All @@ -3797,9 +3797,13 @@ function get_directory_list($rootdir, $excludefile='', $descend=true, $getdirs=f
return $dirs;
}

if (!is_array($excludefiles)) {
$excludefiles = array($excludefiles);
}

while (false !== ($file = readdir($dir))) {
$firstchar = substr($file, 0, 1);
if ($firstchar == '.' or $file == 'CVS' or $file == $excludefile) {
if ($firstchar == '.' or $file == 'CVS' or in_array($file, $excludefiles)) {
continue;
}
$fullfile = $rootdir .'/'. $file;
Expand All @@ -3808,7 +3812,7 @@ function get_directory_list($rootdir, $excludefile='', $descend=true, $getdirs=f
$dirs[] = $file;
}
if ($descend) {
$subdirs = get_directory_list($fullfile, $excludefile, $descend, $getdirs, $getfiles);
$subdirs = get_directory_list($fullfile, $excludefiles, $descend, $getdirs, $getfiles);
foreach ($subdirs as $subdir) {
$dirs[] = $file .'/'. $subdir;
}
Expand Down
12 changes: 5 additions & 7 deletions mod/resource/type/directory/resource.class.php
Expand Up @@ -39,7 +39,7 @@ function display() {
error("The value for 'subdir' contains illegal characters!");
}
$relativepath = "$relativepath$subdir";
if (stripos($relativepath, 'backupdata') !== FALSE) {
if (stripos($relativepath, 'backupdata') !== FALSE or stripos($relativepath, $CFG->moddata) !== FALSE) {
error("Access not allowed!");
}

Expand Down Expand Up @@ -68,7 +68,7 @@ function display() {
"", "", true, update_module_button($cm->id, $course->id, $this->strresource),
navmenu($course, $cm));

if (has_capabilities('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $course->id))) {
if (has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $course->id))) {
echo "<div align=\"right\"><img src=\"$CFG->pixpath/i/files.gif\" height=\"16\" width=\"16\" alt=\"\" />&nbsp".
"<a href=\"$CFG->wwwroot/files/index.php?id={$course->id}&amp;wdir=/{$resource->reference}$subdir\">".
get_string("editfiles")."...</a></div>";
Expand All @@ -80,7 +80,7 @@ function display() {
print_spacer(10,10);
}

$files = get_directory_list("$CFG->dataroot/$relativepath", 'moddata', false, true, true);
$files = get_directory_list("$CFG->dataroot/$relativepath", array($CFG->moddata, 'backupdata'), false, true, true);


if (!$files) {
Expand All @@ -102,9 +102,7 @@ function display() {
"<th align=\"right\" class=\"header date\">$strmodified</th>".
"</tr>";
foreach ($files as $file) {
if ($file == 'backupdata') {
continue;
} else if (is_dir("$CFG->dataroot/$relativepath/$file")) { // Must be a directory
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"));
Expand Down Expand Up @@ -157,7 +155,7 @@ function setup($form) {

parent::setup($form);

$rawdirs = get_directory_list("$CFG->dataroot/{$this->course->id}", 'moddata', true, true, false);
$rawdirs = get_directory_list("$CFG->dataroot/{$this->course->id}", array($CFG->moddata, 'backupdata'), true, true, false);
$dirs = array();
foreach ($rawdirs as $rawdir) {
$dirs[$rawdir] = $rawdir;
Expand Down
2 changes: 1 addition & 1 deletion mod/resource/type/ims/deploy.php
Expand Up @@ -78,7 +78,7 @@
/// Security Constraints (sesskey and isteacheredit)
if (!confirm_sesskey()) {
error(get_string('confirmsesskeybad', 'error'));
} else if (!has_capabilities('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $courseid))) {
} else if (!has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $courseid))) {
error(get_string('onlyeditingteachers', 'error'));
}

Expand Down
2 changes: 1 addition & 1 deletion mod/resource/type/ims/resource.class.php
Expand Up @@ -334,7 +334,7 @@ function display() {

/// If there are any error, show it instead of the resource page
if ($errorcode) {
if (!has_capabilities('moodle/course:activityvisibility', get_context_instance(CONTEXT_COURSE, $course->id))) {
if (!has_capability('moodle/course:activityvisibility', get_context_instance(CONTEXT_COURSE, $course->id))) {
/// Resource not available page
$errortext = get_string('resourcenotavailable','resource');
} else {
Expand Down
4 changes: 2 additions & 2 deletions mod/resource/version.php
Expand Up @@ -5,8 +5,8 @@
// This fragment is called by /admin/index.php
////////////////////////////////////////////////////////////////////////////////

$module->version = 2006091201;
$module->requires = 2006080900; // Requires this Moodle version
$module->version = 2006091700;
$module->requires = 2006091700; // Requires this Moodle version
$module->cron = 0;

?>

0 comments on commit 7f5bc80

Please sign in to comment.