2009-05-01 14:30:11 +02:00
< ? php
/**
2016-05-05 09:20:07 +02:00
* EGroupware - Filemanager - test script
2009-05-01 14:30:11 +02:00
*
* @ link http :// www . egroupware . org
* @ package filemanager
* @ author Ralf Becker < RalfBecker - AT - outdoor - training . de >
2016-05-05 09:20:07 +02:00
* @ copyright ( c ) 2009 - 16 by Ralf Becker < RalfBecker - AT - outdoor - training . de >
2009-05-01 14:30:11 +02:00
* @ license http :// opensource . org / licenses / gpl - license . php GPL - GNU General Public License
* @ version $Id $
*/
2016-05-05 09:20:07 +02:00
use EGroupware\Api ;
use EGroupware\Api\Vfs ;
2009-05-01 14:30:11 +02:00
$GLOBALS [ 'egw_info' ][ 'flags' ] = array (
'currentapp' => 'filemanager'
);
include ( '../header.inc.php' );
2016-05-05 09:20:07 +02:00
if ( ! ( $path = Api\Cache :: getSession ( 'filemanger' , 'test' )))
2009-05-03 20:48:36 +02:00
{
$path = '/home/' . $GLOBALS [ 'egw_info' ][ 'user' ][ 'account_lid' ];
}
2009-05-01 14:30:11 +02:00
if ( isset ( $_REQUEST [ 'path' ])) $path = $_REQUEST [ 'path' ];
2016-05-05 09:20:07 +02:00
echo Api\Html :: form ( " <p>Path: " . Api\Html :: input ( 'path' , $path , 'text' , 'size="40"' ) .
Api\Html :: submit_button ( '' , lang ( 'Submit' )) . " </p> \n " , array (), '' , '' , '' , '' , 'GET' );
2009-05-01 14:30:11 +02:00
if ( isset ( $path ) && ! empty ( $path ))
{
if ( $path [ 0 ] != '/' )
{
2016-05-05 09:20:07 +02:00
throw new Api\Exception\WrongUserinput ( 'Not an absolute path!' );
2009-05-01 14:30:11 +02:00
}
2016-05-05 09:20:07 +02:00
Api\Cache :: setSession ( 'filemanger' , 'test' , $path );
2009-05-03 20:48:36 +02:00
2009-05-01 14:30:11 +02:00
echo " <h2> " ;
foreach ( explode ( '/' , $path ) as $n => $part )
{
$p .= ( $p != '/' ? '/' : '' ) . $part ;
2016-05-05 09:20:07 +02:00
echo ( $n > 1 ? ' / ' : '' ) . Api\Html :: a_href ( $n ? $part : ' / ' , '/filemanager/test.php' , array ( 'path' => $p ));
2009-05-01 14:30:11 +02:00
}
echo " </h2> \n " ;
2016-05-05 09:20:07 +02:00
echo " <p><b>egw_vfs::propfind(' $path ')</b>= " . array2string ( Vfs :: propfind ( $path )) . " </p> \n " ;
echo " <p><b>egw_vfs::resolve_url(' $path ')</b>= " . array2string ( Vfs :: resolve_url ( $path )) . " </p> \n " ;
2013-04-10 18:45:20 +02:00
2016-05-05 09:20:07 +02:00
$is_dir = Vfs :: is_dir ( $path );
2009-05-01 14:30:11 +02:00
echo " <p><b>is_dir(' $path ')</b>= " . array2string ( $is_dir ) . " </p> \n " ;
$time = microtime ( true );
2016-05-05 09:20:07 +02:00
$stat = Vfs :: stat ( $path );
2010-04-29 14:35:38 +02:00
$stime = number_format ( 1000 * ( microtime ( true ) - $time ), 1 );
2009-05-01 14:30:11 +02:00
2016-05-05 09:20:07 +02:00
$time2 = microtime ( true );
if ( $is_dir ) // && ($d = Vfs::opendir($path)))
2009-05-01 14:30:11 +02:00
{
$files = array ();
2010-04-29 14:35:38 +02:00
//while(($file = readdir($d)))
2016-05-05 09:20:07 +02:00
foreach ( Vfs :: scandir ( $path ) as $file )
2009-05-01 14:30:11 +02:00
{
2016-05-05 09:20:07 +02:00
if ( Vfs :: is_readable ( $fpath = Vfs :: concat ( $path , $file )))
2009-05-01 14:30:11 +02:00
{
2016-05-05 09:20:07 +02:00
$file = Api\Html :: a_href ( $file , '/filemanager/test.php' , array ( 'path' => $fpath ));
2009-05-01 14:30:11 +02:00
}
2016-05-05 09:20:07 +02:00
$file .= ' (' . Vfs :: mime_content_type ( $fpath ) . ')' ;
2009-05-01 14:30:11 +02:00
$files [] = $file ;
}
2010-04-29 14:35:38 +02:00
//closedir($d);
2016-05-05 09:20:07 +02:00
$time2f = number_format ( 1000 * ( microtime ( true ) - $time2 ), 1 );
echo " <p> " . ( $files ? 'Directory' : 'Empty directory' ) . " took $time2f ms</p> \n " ;
2010-04-29 14:35:38 +02:00
if ( $files ) echo '<ol><li>' . implode ( " </li> \n <li> " , $files ) . '</ol>' . " \n " ;
2009-05-01 14:30:11 +02:00
}
2016-05-05 09:20:07 +02:00
echo " <p><b>stat(' $path ')</b> took $stime ms (mode = " . ( isset ( $stat [ 'mode' ]) ? sprintf ( '%o' , $stat [ 'mode' ]) . ' = ' . Vfs :: int2mode ( $stat [ 'mode' ]) : 'NULL' ) . ')' ;
2009-05-01 14:30:11 +02:00
if ( is_array ( $stat ))
{
_debug_array ( $stat );
}
else
{
echo " <p> " . array2string ( $stat ) . " </p> \n " ;
}
2016-05-05 09:20:07 +02:00
echo " <p><b>egw_vfs::is_readable(' $path ')</b>= " . array2string ( Vfs :: is_readable ( $path )) . " </p> \n " ;
echo " <p><b>egw_vfs::is_writable(' $path ')</b>= " . array2string ( Vfs :: is_writable ( $path )) . " </p> \n " ;
2009-05-01 14:30:11 +02:00
2016-05-05 09:20:07 +02:00
echo " <p><b>is_link(' $path ')</b>= " . array2string ( Vfs :: is_link ( $path )) . " </p> \n " ;
echo " <p><b>readlink(' $path ')</b>= " . array2string ( Vfs :: readlink ( $path )) . " </p> \n " ;
$time3 = microtime ( true );
$lstat = Vfs :: lstat ( $path );
$time3f = number_format ( 1000 * ( microtime ( true ) - $time3 ), 1 );
echo " <p><b>lstat(' $path ')</b> took $time3f ms (mode = " . ( isset ( $lstat [ 'mode' ]) ? sprintf ( '%o' , $lstat [ 'mode' ]) . ' = ' . Vfs :: int2mode ( $lstat [ 'mode' ]) : 'NULL' ) . ')' ;
2009-05-01 14:30:11 +02:00
if ( is_array ( $lstat ))
{
_debug_array ( $lstat );
}
else
{
echo " <p> " . array2string ( $lstat ) . " </p> \n " ;
}
if ( ! $is_dir && $stat )
{
2016-05-05 09:20:07 +02:00
echo " <p><b>egw_vfs::mime_content_type(' $path ')</b>= " . array2string ( Vfs :: mime_content_type ( $path )) . " </p> \n " ;
echo " <p><b>filesize(Vfs::PREFIX.' $path ')</b>= " . array2string ( filesize ( Vfs :: PREFIX . $path )) . " </p> \n " ;
echo " <p><b>bytes(file_get_contents(Vfs::PREFIX.' $path '))</b>= " . array2string ( bytes ( file_get_contents ( Vfs :: PREFIX . $path ))) . " </p> \n " ;
2009-05-01 14:30:11 +02:00
}
}
2016-05-05 09:20:07 +02:00
$GLOBALS [ 'egw' ] -> framework -> footer ();