예제 #1
0
 /**
 * copy a file creating all path on the way if needed
 * @param string $source the source path from dataroot
 * @param string $dest the dest path from dataroot
 * @param string $pathbase the base path
 */
 function filesystem_copy_file($source, $dest, $pathbase = null)
 {
     global $CFG;
     if (is_null($pathbase)) {
         $pathbase = $CFG->dataroot . '/';
     } elseif ($pathbase === '') {
         $pathbase = '';
     } else {
         $pathbase = $pathbase . '/';
     }
     if (@$CFG->filedebug) {
         mtrace("copying file <i>{$pathbase}{$source}</i> to <i>{$pathbase}{$dest}</i><br/>");
     }
     if (!filesystem_file_exists($source, $pathbase)) {
         return -1;
     }
     $parts = pathinfo($dest);
     if (!filesystem_is_dir($parts['dirname'], $pathbase)) {
         filesystem_create_dir($parts['dirname'], $pathbase);
     }
     return copy($pathbase . $source, $pathbase . $dest);
 }
예제 #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
/**
* copy a file creating all path on the way if needed
* @param source the source path from dataroot
* @param dest the dest path from dataroot
*/
function filesystem_copy_file($source, $dest)
{
    global $CFG;
    if ($CFG->debug > 8) {
        mtrace("copying file <i>{$source}</i> to <i>{$dest}</i><br/>");
    }
    if (!filesystem_file_exists($source)) {
        return -1;
    }
    $parts = pathinfo($dest);
    if (!filesystem_is_dir($parts['dirname'])) {
        filesystem_create_dir($parts['dirname']);
    }
    return copy($CFG->dataroot . '/' . $source, $CFG->dataroot . '/' . $dest);
}