예제 #1
0
/**
 * Get the directories of the supplied path as a radio button tree.
 *
 * @todo fp> Make a DirTree class (those static hacks suck)
 *
 * @param FileRoot A single root or NULL for all available.
 * @param string the root path to use
 * @param boolean add radio buttons ?
 * @param string used by recursion
 * @param string what kind of action do the user ( we need this to check permission )
 * 			fp>asimo : in what case can this be something else than "view" ?
 * 			asimo>fp : on the _file_upload.view, we must show only those roots where current user has permission to add files
 * @return string
 */
function get_directory_tree($Root = NULL, $ads_full_path = NULL, $ads_selected_full_path = NULL, $radios = false, $rds_rel_path = NULL, $is_recursing = false, $action = 'view')
{
    static $js_closeClickIDs;
    // clickopen IDs that should get closed
    static $instance_ID = 0;
    static $fm_highlight;
    global $current_User;
    // A folder might be highlighted (via "Locate this directory!")
    if (!isset($fm_highlight)) {
        $fm_highlight = param('fm_highlight', 'string', '');
    }
    if (!$is_recursing) {
        // This is not a recursive call (yet):
        // Init:
        $instance_ID++;
        $js_closeClickIDs = array();
        $ret = '<ul class="clicktree">';
    } else {
        $ret = '';
    }
    // ________________________ Handle Roots ______________________
    if ($Root === NULL) {
        // We want to list all roots:
        $FileRootCache =& get_FileRootCache();
        $_roots = $FileRootCache->get_available_FileRoots();
        foreach ($_roots as $l_Root) {
            if (!$current_User->check_perm('files', $action, false, $l_Root)) {
                // current user does not have permission to "view" (or other $action) this root
                continue;
            }
            $subR = get_directory_tree($l_Root, $l_Root->ads_path, $ads_selected_full_path, $radios, '', true);
            if (!empty($subR['string'])) {
                $ret .= '<li>' . $subR['string'] . '</li>';
            }
        }
    } else {
        // We'll go through files in current dir:
        $Nodelist = new Filelist($Root, trailing_slash($ads_full_path));
        check_showparams($Nodelist);
        $Nodelist->load();
        $Nodelist->sort('name');
        $has_sub_dirs = $Nodelist->count_dirs();
        $id_path = 'id_path_' . $instance_ID . md5($ads_full_path);
        $r['string'] = '<span class="folder_in_tree"';
        if ($ads_full_path == $ads_selected_full_path) {
            // This is the current open path
            $r['opened'] = true;
            if ($fm_highlight && $fm_highlight == substr($rds_rel_path, 0, -1)) {
                $r['string'] .= ' id="fm_highlighted"';
                unset($fm_highlight);
            }
        } else {
            $r['opened'] = NULL;
        }
        $r['string'] .= '>';
        if ($radios) {
            // Optional radio input to select this path:
            $root_and_path = format_to_output(implode('::', array($Root->ID, $rds_rel_path)), 'formvalue');
            $r['string'] .= '<input type="radio" name="root_and_path" value="' . $root_and_path . '" id="radio_' . $id_path . '"';
            if ($r['opened']) {
                // This is the current open path
                $r['string'] .= ' checked="checked"';
            }
            //.( ! $has_sub_dirs ? ' style="margin-right:'.get_icon( 'collapse', 'size', array( 'size' => 'width' ) ).'px"' : '' )
            $r['string'] .= ' /> &nbsp; &nbsp;';
        }
        // Folder Icon + Name:
        $url = regenerate_url('root,path', 'root=' . $Root->ID . '&amp;path=' . $rds_rel_path);
        $label = action_icon(T_('Open this directory in the file manager'), 'folder', $url) . '<a href="' . $url . '"
			title="' . T_('Open this directory in the file manager') . '">' . (empty($rds_rel_path) ? $Root->name : basename($ads_full_path)) . '</a>';
        // Handle potential subdir:
        if (!$has_sub_dirs) {
            // No subdirs
            $r['string'] .= get_icon('expand', 'noimg', array('class' => '')) . '&nbsp;' . $label . '</span>';
        } else {
            // Process subdirs
            $r['string'] .= get_icon('collapse', 'imgtag', array('onclick' => 'toggle_clickopen(\'' . $id_path . '\');', 'id' => 'clickimg_' . $id_path, 'style' => 'margin:0 2px')) . '&nbsp;' . $label . '</span>' . '<ul class="clicktree" id="clickdiv_' . $id_path . '">' . "\n";
            while ($l_File =& $Nodelist->get_next('dir')) {
                $rSub = get_directory_tree($Root, $l_File->get_full_path(), $ads_selected_full_path, $radios, $l_File->get_rdfs_rel_path(), true);
                if ($rSub['opened']) {
                    // pass opened status on, if given
                    $r['opened'] = $rSub['opened'];
                }
                $r['string'] .= '<li>' . $rSub['string'] . '</li>';
            }
            if (!$r['opened']) {
                $js_closeClickIDs[] = $id_path;
            }
            $r['string'] .= '</ul>';
        }
        if ($is_recursing) {
            return $r;
        } else {
            $ret .= '<li>' . $r['string'] . '</li>';
        }
    }
    if (!$is_recursing) {
        $ret .= '</ul>';
        if (!empty($js_closeClickIDs)) {
            // there are IDs of checkboxes that we want to close
            $ret .= "\n" . '<script type="text/javascript">toggle_clickopen( \'' . implode("' );\ntoggle_clickopen( '", $js_closeClickIDs) . "' );\n</script>";
        }
    }
    return $ret;
}
예제 #2
0
$UserSettings->param_Request('fm_hide_dirtree', 'fm_hide_dirtree', 'integer', 0, true);
/**
 * Filelist
 */
$fm_Filelist = new Filelist($fm_FileRoot, $ads_list_path);
$Debuglog->add('FM _rds_list_path: ' . var_export($fm_Filelist->_rds_list_path, true), 'files');
param('fm_filter', 'string', NULL, true);
param('fm_filter_regex', 'integer', 0, true);
$fm_Filelist->set_Filter($fm_filter, $fm_filter_regex);
if ($UserSettings->param_Request('fm_dirsnotattop', 'fm_dirsnotattop', 'integer', 0)) {
    $fm_Filelist->_dirs_not_at_top = true;
}
if ($UserSettings->param_Request('fm_recursivedirsize', 'fm_recursivedirsize', 'integer', 0)) {
    $fm_Filelist->_use_recursive_dirsize = true;
}
check_showparams($fm_Filelist);
if (param('fm_flatmode', 'boolean', NULL, true)) {
    $fm_Filelist->flatmode = true;
}
/*
 * Load Filelist (with meta data):
 */
$fm_Filelist->load();
// Sort Filelist
param('fm_order', 'string', NULL, true);
if (!in_array($fm_order, array('name', 'path', 'type', 'size', 'lastmod', 'perms', 'fsowner', 'fsgroup'))) {
    $fm_order = NULL;
}
param('fm_orderasc', 'boolean', NULL, true);
$fm_Filelist->sort($fm_order, $fm_orderasc);
switch ($action) {