示例#1
0
文件: lib.php 项目: jamesmcq/elis
    /**
     * Determine whether the root folder is valid
     * @return  string
     */
    private static function root_folder_is_valid($data) {
        $repoisup = false;

    /// Validate the path, if we can.
        if ($repo = repository_factory::factory()) {
            $repoisup = $repo->is_configured() && $repo->verify_setup();
            if ($repoisup) {
                if (elis_files_validate_path($data)) {
                    $valid = '<span class="pathok" style="color:green;">&#x2714;</span>';
                } else {
                    $valid = '<span class="patherror" style="color:red;">&#x2718;</span>';
                }
            }
        }
        if (!isset($valid)) {
            $valid = '';
        }

        return $valid;
    }
示例#2
0
文件: lib.php 项目: jamesmcq/elis
/**
 * Recursively determine whether the specified path is actually valid on the
 * configured repository.
 *
 * @param string $path
 * @return bool True if the path is valid, False otherwise.
 */
function elis_files_validate_path($path, $folders = null) {
    if ($path == '/') {
        return true;
    }

/// Remove any extraneous slashes from the ends of the string
    $path = trim($path, '/');

    $parts = explode('/', $path);

/// Initialize the folder structure if a structure piece wasn't passed to this function.
    if ($folders == null) {
        $folders = elis_files_folder_structure();
    }

/// Get the first piece from the list of path elements.
    $pathpiece = array_shift($parts);

    if (!empty($folders)) {
        foreach ($folders as $folder) {
            if ($folder['name'] == $pathpiece) {
            /// If there are no more path elements, we've succeeded!
                if (empty($parts)) {
                    return true;

            /// If there are path elements left but no children from the current
            /// folder, we've failed.
                } else if (!empty($parts) && empty($folder['children'])) {
                    return false;

            /// Otherwise, keep looking below.
                } else {
                    return elis_files_validate_path(implode('/', $parts), $folder['children']);
                }
            }
        }
    }

    return false;
}