Index: units/helpers/file_helper.php
===================================================================
--- units/helpers/file_helper.php (revision 14188)
+++ units/helpers/file_helper.php (working copy)
@@ -283,6 +283,91 @@
}
/**
+ * Copies all files and directories from $source to $destination directory. Create destination directory, when missing.
+ *
+ * @param string $source
+ * @param string $destination
+ * @return bool
+ */
+ function copyFolderRecursive($source, $destination)
+ {
+ if ( substr($source, -1) == DIRECTORY_SEPARATOR ) {
+ $source = substr($source, 0, -1);
+ $destination .= DIRECTORY_SEPARATOR . basename($source);
+ }
+
+ $dir = opendir($source);
+ $result = $this->CheckFolder($destination);
+
+ if (!$result) {
+ // failed to create target directory
+ return false;
+ }
+
+ while ( false !== ($file = readdir($dir)) ) {
+ if ($file == '.' || $file == '..') {
+ continue;
+ }
+
+ if ( is_dir($source . DIRECTORY_SEPARATOR . $file) ) {
+ $result = $this->copyFolderRecursive($source . DIRECTORY_SEPARATOR . $file, $destination . DIRECTORY_SEPARATOR . $file);
+ }
+ else {
+ $result = copy($source . DIRECTORY_SEPARATOR . $file, $destination . DIRECTORY_SEPARATOR . $file);
+ }
+
+ if (!$result) {
+ trigger_error('Cannot create file/directory "' . $destination . DIRECTORY_SEPARATOR . $file . '"', E_USER_WARNING);
+ break;
+ }
+ }
+
+ closedir($dir);
+
+ return $result;
+ }
+
+ /**
+ * Copies all files from $source to $destination directory. Create destination directory, when missing.
+ *
+ * @param string $source
+ * @param string $destination
+ * @return bool
+ */
+ function copyFolder($source, $destination)
+ {
+ if ( substr($source, -1) == DIRECTORY_SEPARATOR ) {
+ $source = substr($source, 0, -1);
+ $destination .= DIRECTORY_SEPARATOR . basename($source);
+ }
+
+ $dir = opendir($source);
+ $result = $this->CheckFolder($destination);
+
+ if (!$result) {
+ // failed to create target directory
+ return false;
+ }
+
+ while ( false !== ($file = readdir($dir)) ) {
+ if ($file == '.' || $file == '..' || !is_file($source . DIRECTORY_SEPARATOR . $file)) {
+ continue;
+ }
+
+ $result = copy($source . DIRECTORY_SEPARATOR . $file, $destination . DIRECTORY_SEPARATOR . $file);
+
+ if (!$result) {
+ trigger_error('Cannot create file "' . $destination . DIRECTORY_SEPARATOR . $file . '"', E_USER_WARNING);
+ break;
+ }
+ }
+
+ closedir($dir);
+
+ return $result;
+ }
+
+ /**
* Transforms given path to file into it's url, where each each component is encoded (excluding domain and protocol)
*
* @param string $url