Template::GetAllFolders PHP Method

GetAllFolders() public static method

Returns an array containing the directories tree for the given path.
public static GetAllFolders ( array $p_folders ) : array
$p_folders array
return array $p_folders
    public static function GetAllFolders($p_folders)
    {
        global $Campsite;
        $path = $Campsite['TEMPLATE_DIRECTORY'] . '/';
        if ($dirHandle = opendir($path)) {
            $i = 0;
            while (($file = readdir($dirHandle)) !== false) {
                if ($file != '.' && $file != '..' && is_dir($path . $file)) {
                    $i++;
                    $p_folders[$i] = $path . $file;
                }
            }
        }
        closedir($dirHandle);
        $i = count($p_folders);
        foreach ($p_folders as $folder) {
            if ($subDirHandle = opendir($folder)) {
                while (($file = readdir($subDirHandle)) !== false) {
                    $pathTo = $folder . '/' . $file;
                    if ($file != '.' && $file != '..' && is_dir($pathTo) && !in_array($pathTo, $p_folders)) {
                        $i++;
                        $p_folders[$i] = $pathTo;
                        $p_folders = self::GetAllFolders($p_folders);
                    }
                }
            }
            closedir($subDirHandle);
        }
        sort($p_folders);
        return $p_folders;
    }

Usage Example

示例#1
0
// $articles array:
// The articles that were initially selected to perform the move or duplicate upon.
$templates = array();
for ($i = 0; $i < count($f_template_code); $i++) {
	$tmpTemplate = new Template($f_template_code[$i]);
	$templates[] = $tmpTemplate;
}

if (!Input::IsValid()) {
	camp_html_display_error(getGS('Invalid input: $1', Input::GetErrorString()));
	exit;
}

// Get all the templates
$folders = array();
$folders = Template::GetAllFolders($folders);
$i = 1;
foreach ($folders as $folder) {
	$tmpTemplateFolder = substr($folder, strlen($Campsite['TEMPLATE_DIRECTORY']));
	if ($f_current_folder != $tmpTemplateFolder) {
		$folders[$i++] = $tmpTemplateFolder;
	}
}
if ($f_current_folder != '/') {
	$folders[0] = '/';
} else {
	array_shift($folders);
}

//
// This section is executed when the user finally hits the action button.