Fix: Use preg functions

This commit is contained in:
Laurent Destailleur 2009-10-22 00:25:20 +00:00
parent 49e701c645
commit 8c2705707a

View File

@ -168,7 +168,7 @@ if ($_REQUEST['action'] == 'confirm_deletefile' && $_REQUEST['confirm'] == 'yes'
{ {
// Remote file // Remote file
$filename=$file; $filename=$file;
$remotefile=$section.(eregi('[\\\/]$',$section)?'':'/').$file; $remotefile=$section.(preg_match('@[\\\/]$@',$section)?'':'/').$file;
$newremotefileiso=utf8_decode($remotefile); $newremotefileiso=utf8_decode($remotefile);
//print "x".$newremotefileiso; //print "x".$newremotefileiso;
@ -209,7 +209,7 @@ if ($_REQUEST['action'] == 'confirm_deletesection' && $_REQUEST['confirm'] == 'y
{ {
// Remote file // Remote file
$filename=$file; $filename=$file;
$remotefile=$section.(eregi('[\\\/]$',$section)?'':'/').$file; $remotefile=$section.(preg_match('@[\\\/]$@',$section)?'':'/').$file;
$newremotefileiso=utf8_decode($remotefile); $newremotefileiso=utf8_decode($remotefile);
$result=ftp_rmdir($conn_id, $newremotefileiso); $result=ftp_rmdir($conn_id, $newremotefileiso);
@ -252,7 +252,7 @@ if ($_REQUEST['action'] == 'download')
// Remote file // Remote file
$filename=$file; $filename=$file;
$remotefile=$section.(eregi('[\\\/]$',$section)?'':'/').$file; $remotefile=$section.(preg_match('@[\\\/]$@',$section)?'':'/').$file;
$newremotefileiso=utf8_decode($remotefile); $newremotefileiso=utf8_decode($remotefile);
$result=ftp_get($conn_id,$localfile,$newremotefileiso,FTP_BINARY); $result=ftp_get($conn_id,$localfile,$newremotefileiso,FTP_BINARY);
@ -395,8 +395,9 @@ else
$i=0; $i=0;
while ($i < $nboflines && $i < 1000) while ($i < $nboflines && $i < 1000)
{ {
$vals=explode(' +',utf8_encode($buff[$i]),9); $vals=preg_split('@ +@',utf8_encode($buff[$i]),9);
//$vals=preg_split('@ +@','drwxr-xr-x 2 root root 4096 Aug 30 2008 backup_apollon1',9);
//var_dump($vals);
$file=$vals[8]; $file=$vals[8];
if (empty($file)) if (empty($file))
{ {
@ -415,15 +416,20 @@ else
if ($file == '..') $is_directory=1; if ($file == '..') $is_directory=1;
else if (! $rawlisthasfailed) else if (! $rawlisthasfailed)
{ {
if (eregi('^d',$vals[0])) $is_directory=1; if (preg_match('/^d/',$vals[0])) $is_directory=1;
if (eregi('^l',$vals[0])) $is_link=1; if (preg_match('/^l/',$vals[0])) $is_link=1;
} }
else else
{ {
// Remote file // Remote file
$filename=$file; $filename=$file;
$remotefile=$section.(eregi('[\\\/]$',$section)?'':'/').$file; //print "section=".$section.' file='.$file.'X';
//print preg_match('@[\/]$@','aaa/').'Y';
//print preg_match('@[\\\/]$@',"aaa\\").'Y';
$remotefile=$section.(preg_match('@[\\\/]$@',$section)?'':'/').preg_replace('@^[\\\/]@','',$file);
//print 'A'.$remotefile.'A';
$newremotefileiso=utf8_decode($remotefile); $newremotefileiso=utf8_decode($remotefile);
//print 'Z'.$newremotefileiso.'Z';
$is_directory=ftp_isdir($conn_id, $newremotefileiso); $is_directory=ftp_isdir($conn_id, $newremotefileiso);
} }
@ -431,8 +437,8 @@ else
print '<tr '.$bc[$var].'>'; print '<tr '.$bc[$var].'>';
// Name // Name
print '<td>'; print '<td>';
$newsection=$section.(eregi('[\\\/]$',$section)?'':'/').$file; $newsection=$section.(preg_match('@[\\\/]$@',$section)?'':'/').$file;
$newsection=eregi_replace('[\\\/][^\\\/]+[\\\/]\.\.$','/',$newsection); // Change aaa/xxx/.. to new aaa $newsection=preg_replace('@[\\\/][^\\\/]+[\\\/]\.\.$@','/',$newsection); // Change aaa/xxx/.. to new aaa
if ($is_directory) print '<a href="'.$_SERVER["PHP_SELF"].'?section='.urlencode($newsection).'">'; if ($is_directory) print '<a href="'.$_SERVER["PHP_SELF"].'?section='.urlencode($newsection).'">';
print $file; print $file;
if ($is_directory) print '</a>'; if ($is_directory) print '</a>';
@ -580,7 +586,7 @@ function dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $sect
*/ */
function ftp_isdir($connect_id,$dir) function ftp_isdir($connect_id,$dir)
{ {
if(ftp_chdir($connect_id,$dir)) if (@ftp_chdir($connect_id,$dir))
{ {
ftp_cdup($connect_id); ftp_cdup($connect_id);
return 1; return 1;