Changeset 394

Show
Ignore:
Timestamp:
03/05/07 13:13:41 (2 years ago)
Author:
malte
Message:

introduced ftp-abstraction class thx to draburn

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/gui/client/ftp_choose_dir.php

    r154 r394  
    1515//  |                                                                               | 
    1616//   ------------------------------------------------------------------------------- 
    17  
    18  
    19  
     17require '../include/vfs.php'; 
    2018include '../include/vhcs-lib.php'; 
    2119 
     
    3836$theme_color = $cfg['USER_INITIAL_THEME']; 
    3937 
    40 // functions begin 
    4138 
    42 function cleanPath($path) { 
    43    $result = array(); 
    44    $pathTemp = explode('/', $path); 
    45    if (!$pathTemp[0]) 
    46        $result[] = ''; 
    47    foreach ($pathTemp AS $key => $dir) { 
    48        if ($dir == '..') { 
    49            if (end($result) == '..') { 
    50                $result[] = '..'; 
    51            } elseif (!array_pop($result)) { 
    52                $result[] = '..'; 
    53            } 
    54        } elseif ($dir && $dir != '.') { 
    55            $result[] = $dir; 
    56        } 
    57    } 
    58    if (!end($pathTemp))  
    59        $result[] = ''; 
    60    return implode('/', $result); 
    61 
    62  
    63  
    64 function gen_directories(&$tpl) 
    65 
    66  
    67         global $cur_dir, $cfg, $sql; 
     39function gen_directories( &$tpl ) { 
     40        global $sql; 
     41        $path   = isset($_GET['cur_dir']) ? $_GET['cur_dir'] : ''; 
     42        $domain = $_SESSION['user_logged']; 
    6843         
    69         if(!isset($path)){$path = '';}   
     44        $vfs = new vfs($domain); 
     45        $vfs->setDb($sql); 
     46        $vfs->open(); 
     47        $list = $vfs->ls($path,true); 
    7048         
    71         $domain_name = $_SESSION['user_logged']; 
    72          
    73         $homedir = $cfg['FTP_HOMEDIR']; 
    74  
    75         $dtop = $homedir.'/'.$domain_name; 
    76          
    77         if (!isset($_GET['cur_dir'])) { 
    78                         $cur_dir = '/'; 
    79         } else { 
    80                 $path = cleanPath($path); 
    81                 $_GET['cur_dir'] = eregi_replace("\.\./","",cleanPath($_GET['cur_dir'])); 
    82                 $_GET['cur_dir'] = eregi_replace("\.\.","",$_GET['cur_dir']); 
    83                 $_GET['cur_dir'] = '/'.$_GET['cur_dir']; 
    84                 if ($_GET['cur_dir'] === "/") { 
    85                                 $cur_dir = $_GET['cur_dir']; 
    86                         } else { 
    87                                 $cur_dir = $_GET['cur_dir'].'/'; 
    88                         } 
    89         } 
    90          
    91      
    92         $real_dir = $dtop . $cur_dir; 
    93      
    94         $d = dir($real_dir); 
    95         if(!$d->handle){ 
     49        if (!$list) { 
    9650                set_page_message( tr('Can not open directory !<br>Please contact your administrator !')); 
    97                  
    9851                return; 
    9952        } 
    100         else { 
    101                 while (false !== ($entry = $d->read())) { 
    102                                          
    103                         if ($entry == '.') { 
    104                                 /* */ 
    105                         } 
    106                         else if ($entry == '..') { 
    107                                          
    108                                 $top_dir1 = $cur_dir; 
    109                          
    110                         if ($real_dir != $dtop) { 
    111                                 $top_dir1 = substr($cur_dir,0,strlen($cur_dir)-1); 
    112                         } 
     53 
     54        // Show parent directory link 
     55        $parent = explode('/',$path); 
     56        array_pop($parent); 
     57        $parent = implode('/',$parent); 
     58        $tpl -> assign('ACTION_LINK', ''); 
     59        $tpl -> assign( array( 
     60                                'ACTION' => tr(''), 
     61                                'ICON' => "parent", 
     62                                'DIR_NAME' => tr('Parent Directory'), 
     63                                'LINK' => 'ftp_choose_dir.php?cur_dir=' . $parent, 
     64                        )); 
     65        $tpl -> parse('DIR_ITEM', '.dir_item'); 
     66         
     67        // Show directories 
     68        foreach ($list as $entry) { 
    11369                 
    114                          
    115                         $up = substr($top_dir1,0,strlen($top_dir1) - strlen(strrchr($top_dir1,'/'))); 
    116                         // 1st gose back/up button 
    117                         $tpl -> assign('ACTION_LINK', ''); 
    118                         $tpl -> assign( 
    119                 array( 
    120                                                 'ACTION' => tr(''), 
    121                                                 'ICON' => "parent", 
    122                                                 'DIR_NAME' => tr('Parent Directory'), 
    123                                                 'LINK' => "ftp_choose_dir.php?cur_dir=$up", 
    124  
    125                                           ) 
    126                                 ); 
    127                          
    128                           
    129                          $tpl -> parse('DIR_ITEM', '.dir_item'); 
    130                          
     70                if ( $entry['type'] != VFS_TYPE_DIR ) 
     71                        continue; 
     72         
     73                $dr = $path.'/'.$entry['file']; 
     74                //$tfile = $real_dir.$entry.'/'.'.htaccess'; 
     75         
     76                /*if (file_exists($tfile)) { 
     77                        $image = "locked"; 
    13178                } 
     79                else {*/ 
     80                        $image = "folder"; 
     81                /*}*/ 
    13282         
    133                 else if (is_dir($real_dir.$entry)) { 
    134                         $dr = $cur_dir.$entry; 
    135                         $tfile = $real_dir.$entry.'/'.'.htaccess'; 
    136                  
    137                         if (file_exists($tfile)) { 
    138                                 $image = "locked"; 
    139                         } 
    140                         else { 
    141                                 $image = "folder"; 
    142                         } 
    143                  
    144                         // here gose link to the dir 
    145                           
    146                          $tpl -> assign( 
    147                 array( 
    148                                                 'ACTION' => tr('Protect it'), 
    149                                                 'PROTECT_IT' => "protect_it.php?file=$dr", 
    150                                                 'ICON' => $image, 
    151                                                 'DIR_NAME' => $entry, 
    152                                                 'CHOOSE_IT' => $dr, 
    153                                                 'LINK' => "ftp_choose_dir.php?cur_dir=$dr", 
    154                                           ) 
    155                                 ); 
    156                          $tpl -> parse('ACTION_LINK', 'action_link'); 
    157                          $tpl -> parse('DIR_ITEM', '.dir_item'); 
    158                           
    159                          
    160                 } 
    161                                     
     83                // Create directory link 
     84                $tpl->assign( array( 
     85                        'ACTION' => tr('Protect it'), 
     86                        'PROTECT_IT' => "protect_it.php?file=$dr", 
     87                        'ICON' => $image, 
     88                        'DIR_NAME' => $entry['file'], 
     89                        'CHOOSE_IT' => $dr, 
     90                        'LINK' => "ftp_choose_dir.php?cur_dir=$dr", 
     91                )); 
     92                $tpl->parse('ACTION_LINK', 'action_link'); 
     93                $tpl->parse('DIR_ITEM'   , '.dir_item'); 
    16294        } 
    163         $d->close(); 
    164         } 
    165  
    166         $d = dir($real_dir); 
    167  
    168         if(!$d->handle){ 
    169                 set_page_message( tr('Can not open directory !<br>Please contact your administrator !')); 
    170                  
    171                 return; 
    172         } 
    173         else { 
    174  
    175                 while (false !== ($entry = $d->read())) { 
    176                                          
    177                                              
    178                         if ($entry == '.') { 
    179                                 /* */ 
    180                         } 
    181                         else if ($entry == '..') { 
    182                                 /* */ 
    183                         } 
    184                         else if (!is_dir($real_dir.$entry)) { 
    185  
    186                                 // here gose document 
    187                                 $tpl -> assign('LIST_ITEM', ''); 
    188                          
    189                                   
    190                                  $tpl -> parse('DIR_ITEM', '.dir_item'); 
    191                         }                      
    192                                     
    193         } 
    194     $d->close(); 
    195   } 
    196  
    197  
    19895} 
    19996