Index: documentation/trunk/php/common.php
===================================================================
--- documentation/trunk/php/common.php (revision 27252)
+++ documentation/trunk/php/common.php (revision 27506)
@@ -2,4 +2,8 @@
$base_path = getcwd();
+if (strpos($base_path, 'greenstone') === false)
+{
+ printError('Failed to determine base path...');
+}
// The dokuwiki directory is always in the same place, relative to the PHP
@@ -113,15 +117,15 @@
/** generateID($text) **/
-function mkAllDir($destination_dir, $mode)
-{
- echo '
* Make all directories: ' . $destination_dir . '
' . "\n";
+function mkAllDir($destination_dir)
+{
+ ///cho ' * Make all directories: ' . $destination_dir . '
' . "\n";
$dirs_to_create = array();
$dir = $destination_dir;
while (!empty($dir) && !file_exists($dir))
{
- echo 'Does not exist - create...
';
+ ///cho 'Does not exist - create...
';
array_unshift($dirs_to_create, $dir);
$dir = substr($dir, 0, strrpos($dir, '/'));
- echo 'Testing for the existance of: ' . $dir . '
';
+ ///cho 'Testing for the existance of: ' . $dir . '
';
}
foreach ($dirs_to_create as $dir)
@@ -129,5 +133,5 @@
if (!file_exists($dir))
{
- mkdir($dir, 0755);
+ mkdir($dir, 0775);
}
}
@@ -151,4 +155,9 @@
$_REQUEST[$matches[1]] = $_SERVER['argv'][$i];
}
+ else if (preg_match('/^\-+l/i', $_SERVER['argv'][$i]))
+ {
+ $i++;
+ $_REQUEST['l'] = $_SERVER['argv'][$i];
+ }
else
{
@@ -177,3 +186,65 @@
/** printError($message) **/
+
+/**
+ */
+function recursiveRemove($dir, $base_dir, $remove_this_dir=false)
+{
+ ///cho "recursiveRemove(\"$dir\", \"$base_dir\", $remove_this_dir)
";
+ // Ensure that base_dir is within_dir - safety first!
+ if (strpos($dir, $base_dir) === false)
+ {
+ printError('Can\'t delete directory as is isn\'t within project');
+ }
+ if (is_dir($dir))
+ {
+ if ($dh = opendir($dir))
+ {
+ while (($file = readdir($dh)) !== false)
+ {
+ if (preg_match('/^\./', $file))
+ {
+ // Skip dot files
+ }
+ else
+ {
+ $path = fileCat(array($dir, $file));
+ if (is_dir($path))
+ {
+ recursiveRemove($path, $base_dir, true);
+ }
+ else
+ {
+ unlink($path);
+ if (file_exists($path))
+ {
+ printError('Failed to delete file: ' . $path);
+ }
+ }
+ }
+ }
+ closedir($dh);
+ }
+ else
+ {
+ printError('Failed to open directory for reading: ' . $dir);
+ }
+ // Now that the directory is (hopefully) empty, we can delete it if
+ // required to
+ if ($remove_this_dir)
+ {
+ rmdir($dir);
+ if (file_exists($dir))
+ {
+ printError('Failed to remove directory: ' . $dir);
+ }
+ }
+ }
+ else
+ {
+ printError('Can\'t recursive delete - not a directory: ' . $dir);
+ }
+}
+/** recursiveRemove() **/
+
?>