ソースを参照

Feature #306 - Moving the function rmdirr() into the main API file.

Ivan Tcholakov 15 年 前
コミット
d9e28e4439

+ 0 - 1
main/coursecopy/classes/CourseArchiver.class.php

@@ -25,7 +25,6 @@
 */
 
 require_once 'Course.class.php';
-require_once api_get_path(LIBRARY_PATH).'rmdirr.lib.php';
 require_once api_get_path(LIBRARY_PATH).'pclzip/pclzip.lib.php';
 
 /**

+ 0 - 1
main/coursecopy/classes/CourseRecycler.class.php

@@ -25,7 +25,6 @@
 */
 
 require_once 'Course.class.php';
-require_once api_get_path(LIBRARY_PATH).'rmdirr.lib.php';
 
 /**
  * Class to delete items from a Dokeos-course

+ 0 - 1
main/coursecopy/classes/CourseRestorer.class.php

@@ -37,7 +37,6 @@ require_once 'Learnpath.class.php';
 require_once 'Survey.class.php';
 require_once 'SurveyQuestion.class.php';
 require_once 'Glossary.class.php';
-require_once api_get_path(LIBRARY_PATH).'rmdirr.lib.php';
 require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
 
 define('FILE_SKIP', 1);

+ 0 - 1
main/coursecopy/classes/DummyCourseCreator.class.php

@@ -36,7 +36,6 @@ require_once 'ForumPost.class.php';
 require_once 'CourseDescription.class.php';
 require_once 'Learnpath.class.php';
 require_once 'CourseRestorer.class.php';
-require_once api_get_path(LIBRARY_PATH).'rmdirr.lib.php';
 
 class DummyCourseCreator
 {

+ 54 - 1
main/inc/lib/main_api.lib.php

@@ -2355,7 +2355,7 @@ function api_time_to_hms($seconds) {
 	return "$hours:$min:$sec";
 }
 
-// TODO: This function is to be simplified. File access modes to be implemented. rmdirr() from rmdirr.lib.php to be moved here, next to this function.
+// TODO: This function is to be simplified. File access modes to be implemented.
 /**
  * function adapted from a php.net comment
  * copy recursively a folder
@@ -2398,6 +2398,59 @@ function copyr($source, $dest, $exclude = array(), $copied_files = array()) {
 	return $files;
 }
 
+/**
+ * Deletes a file, or a folder and its contents
+ *
+ * @author      Aidan Lister <aidan@php.net>
+ * @version     1.0.3
+ * @param       string   $dirname    Directory to delete
+ * @return      bool     Returns TRUE on success, FALSE on failure
+ * @link http://aidanlister.com/2004/04/recursively-deleting-a-folder-in-php/
+ * @author		Yannick Warnier, adaptation for the Dokeos LMS, April, 2008
+ * @author		Ivan Tcholakov, a sanity check about Directory class creation has been added, September, 2009
+ */
+function rmdirr($dirname) {
+	// A sanity check
+	if (!file_exists($dirname)) {
+		return false;
+	}
+
+	// Simple delete for a file
+	if (is_file($dirname) || is_link($dirname)) {
+		$res = unlink($dirname);
+		if ($res === false) {
+			error_log(__FILE__.' line '.__LINE__.': '.((bool)ini_get('track_errors') ? $php_errormsg : 'error not recorded because track_errors is off in your php.ini'), 0);
+		}
+		return $res;
+	}
+
+	// Loop through the folder
+	$dir = dir($dirname);
+	// A sanity check
+	$is_object_dir = is_object($dir);
+	if ($is_object_dir) {
+		while (false !== $entry = $dir->read()) {
+			// Skip pointers
+			if ($entry == '.' || $entry == '..') {
+				continue;
+			}
+
+			// Recurse
+			rmdirr("$dirname/$entry");
+		}
+	}
+
+	// Clean up
+	if ($is_object_dir) {
+		$dir->close();
+	}
+	$res = rmdir($dirname);
+	if ($res === false) {
+		error_log(__FILE__.' line '.__LINE__.': '.((bool)ini_get('track_errors') ? $php_errormsg : 'error not recorded because track_errors is off in your php.ini'), 0);
+	}
+	return $res;
+}
+
 // TODO: chmodr() is a better name. Some corrections are needed.
 function api_chmod_R($path, $filemode) {
 	if (!is_dir($path)) {

+ 0 - 53
main/inc/lib/rmdirr.lib.php

@@ -1,53 +0,0 @@
-<?php
-/**
- * Delete a file, or a folder and its contents
- *
- * @author      Aidan Lister <aidan@php.net>
- * @version     1.0.3
- * @param       string   $dirname    Directory to delete
- * @return      bool     Returns TRUE on success, FALSE on failure
- * @link http://aidanlister.com/2004/04/recursively-deleting-a-folder-in-php/
- * @author		Yannick Warnier, adaptation for the Dokeos LMS, April, 2008
- * @author		Ivan Tcholakov, a sanity check about Directory class creation has been added, September, 2009
- */
-function rmdirr($dirname) {
-	// A sanity check
-	if (!file_exists($dirname)) {
-		return false;
-	}
-
-	// Simple delete for a file
-	if (is_file($dirname) || is_link($dirname)) {
-		$res = unlink($dirname);
-		if ($res === false) {
-			error_log(__FILE__.' line '.__LINE__.': '.(ini_get('track_errors') != false ? $php_errormsg : 'error not recorded because track_errors is off in your php.ini'), 0);
-		}
-		return $res;
-	}
-
-	// Loop through the folder
-	$dir = dir($dirname);
-	// A sanity check
-	$is_object_dir = is_object($dir);
-	if ($is_object_dir) {
-		while (false !== $entry = $dir->read()) {
-			// Skip pointers
-			if ($entry == '.' || $entry == '..') {
-				continue;
-			}
-
-			// Recurse
-			rmdirr("$dirname/$entry");
-		}
-	}
-
-	// Clean up
-	if ($is_object_dir) {
-		$dir->close();
-	}
-	$res = rmdir($dirname);
-	if ($res === false) {
-		error_log(__FILE__.' line '.__LINE__.': '.(ini_get('track_errors') != false ? $php_errormsg : 'error not recorded because track_errors is off in your php.ini'), 0);
-	}
-	return $res;
-}

+ 0 - 1
main/newscorm/lp_controller.php

@@ -51,7 +51,6 @@ if ($is_allowed_in_course == false){
 	api_not_allowed(true);
 }
 
-require_once api_get_path(LIBRARY_PATH).'rmdirr.lib.php';
 require_once api_get_path(LIBRARY_PATH).'fckeditor/fckeditor.php';
 $lpfound = false;
 

+ 0 - 1
tests/rmdirr.lib.test_standalone.php

@@ -21,7 +21,6 @@ $_test_sys_library_path = $_test_sys_code_path.'inc/lib/';
 
 require_once($_current_dir.'simpletest/unit_tester.php');
 require_once($_sys_include_path.'global.inc.php');
-require_once($_sys_library_path.'rmdirr.lib.php');
 
 //header('Content-Type: text/html; charset=' . $charset);
 header('Content-Type: text/html; charset=' . 'UTF-8');