예제 #1
0
 /**
 * copies recursively a subtree from a location to another
 * @param string $source the source path from dataroot
 * @param string $dest the dest path from dataroot
 * @param string $pathbase the base path
 * @return void
 */
 function filesystem_copy_tree($source, $dest, $pathbase = null)
 {
     global $CFG;
     if (is_null($pathbase)) {
         $pathbase = $CFG->dataroot . '/';
     } elseif ($pathbase === '') {
         $pathbase = '';
     } else {
         $pathbase = $pathbase . '/';
     }
     if (@$CFG->filedebug) {
         mtrace("copying tree <i>{$pathbase}{$source}</i> to <i>{$pathbase}{$dest}</i><br/>");
     }
     if (file_exists($dest) && !filesystem_is_dir($dest, $pathbase)) {
         return;
     }
     if (!filesystem_is_dir($dest, $pathbase)) {
         filesystem_create_dir($dest, FS_RECURSIVE, $pathbase);
     }
     $files = array();
     $files = filesystem_scan_dir($source, FS_SHOW_HIDDEN, FS_ALL_ENTRIES, $pathbase);
     foreach ($files as $aFile) {
         if ($aFile == '.' || $aFile == '..') {
             next;
         }
         if (filesystem_is_dir("{$source}/{$aFile}", $pathbase)) {
             filesystem_create_dir("{$dest}/{$aFile}", FS_NON_RECURSIVE, $pathbase);
             if (count(filesystem_is_dir("{$source}/{$aFile}", $pathbase)) != 0) {
                 filesystem_copy_tree("{$source}/{$aFile}", "{$dest}/{$aFile}", $pathbase);
             }
         } else {
             filesystem_copy_file("{$source}/{$aFile}", "{$dest}/{$aFile}", $pathbase);
         }
     }
 }
예제 #2
0
/**
 * Get available templates for defining a new virtual host.
 * @return array The availables templates, or EMPTY array.
 */
function vmoodle_get_available_templates()
{
    global $CFG;
    // Scans the templates.
    if (!filesystem_file_exists('vmoodle', $CFG->dataroot)) {
        mkdir($CFG->dataroot . '/vmoodle');
    }
    $dirs = filesystem_scan_dir('vmoodle', FS_IGNORE_HIDDEN, FS_ONLY_DIRS, $CFG->dataroot);
    $vtemplates = preg_grep("/^(.*)_vmoodledata\$/", $dirs);
    // Retrieves template(s) name(s).
    $templatesarray = array();
    if ($vtemplates) {
        foreach ($vtemplates as $vtemplatedir) {
            preg_match("/^(.*)_vmoodledata/", $vtemplatedir, $matches);
            $templatesarray[$matches[1]] = $matches[1];
            if (!isset($first)) {
                $first = $matches[1];
            }
        }
    }
    $templatesarray[] = get_string('reactivetemplate', 'local_vmoodle');
    return $templatesarray;
}
예제 #3
0
/**
* copies recursively a subtree from a location to another
* @param source the source path from dataroot
* @param dest the dest path from dataroot
* @return void
*/
function filesystem_copy_tree($source, $dest)
{
    global $CFG;
    if ($CFG->debug > 8) {
        mtrace("copying tree <i>{$source}</i> to <i>{$dest}</i><br/>");
    }
    if (file_exists($dest) && !filesystem_is_dir($dest)) {
        return;
    }
    if (!filesystem_is_dir($dest)) {
        filesystem_create_dir($dest, FS_RECURSIVE);
    }
    $files = array();
    $files = filesystem_scan_dir($source);
    foreach ($files as $aFile) {
        if ($aFile == '.' || $aFile == '..') {
            next;
        }
        if (filesystem_is_dir("{$source}/{$aFile}")) {
            filesystem_create_dir("{$dest}/{$aFile}", FS_NON_RECURSIVE);
            if (count(filesystem_is_dir("{$source}/{$aFile}")) != 0) {
                filesystem_copy_tree("{$source}/{$aFile}", "{$dest}/{$aFile}");
            }
        } else {
            filesystem_copy_file("{$source}/{$aFile}", "{$dest}/{$aFile}");
        }
    }
}