mirror of
https://github.com/misterunknown/ifm.git
synced 2025-08-09 17:46:31 +02:00
added server-side search function
This commit is contained in:
120
build/libifm.php
120
build/libifm.php
@@ -2206,6 +2206,7 @@ function IFM( params ) {
|
|||||||
case "zipnload": $this->zipnload( $_REQUEST); break;
|
case "zipnload": $this->zipnload( $_REQUEST); break;
|
||||||
case "remoteUpload": $this->remoteUpload( $_REQUEST ); break;
|
case "remoteUpload": $this->remoteUpload( $_REQUEST ); break;
|
||||||
case "multidelete": $this->deleteMultipleFiles( $_REQUEST ); break;
|
case "multidelete": $this->deleteMultipleFiles( $_REQUEST ); break;
|
||||||
|
case "searchItems": $this->searchItems( $_REQUEST ); break;
|
||||||
case "getFolderTree": $this->getFolderTree( $_REQUEST ); break;
|
case "getFolderTree": $this->getFolderTree( $_REQUEST ); break;
|
||||||
default:
|
default:
|
||||||
echo json_encode( array( "status" => "ERROR", "message" => "Invalid api action given" ) );
|
echo json_encode( array( "status" => "ERROR", "message" => "Invalid api action given" ) );
|
||||||
@@ -2253,52 +2254,8 @@ function IFM( params ) {
|
|||||||
elseif( $result == "." ) {}
|
elseif( $result == "." ) {}
|
||||||
elseif( $result != ".." && substr( $result, 0, 1 ) == "." && $this->config['showhiddenfiles'] != 1 ) {}
|
elseif( $result != ".." && substr( $result, 0, 1 ) == "." && $this->config['showhiddenfiles'] != 1 ) {}
|
||||||
else {
|
else {
|
||||||
$item = array();
|
$item = $this->getItemInformation( $result );
|
||||||
$item["name"] = $result;
|
if( $item['type'] == "dir" ) $dirs[] = $item;
|
||||||
if( is_dir( $result ) ) {
|
|
||||||
$item["type"] = "dir";
|
|
||||||
if( $result == ".." )
|
|
||||||
$item["icon"] = "icon icon-up-open";
|
|
||||||
else
|
|
||||||
$item["icon"] = "icon icon-folder-empty";
|
|
||||||
} else {
|
|
||||||
$item["type"] = "file";
|
|
||||||
if( in_array( substr( $result, -7 ), array( ".tar.gz", ".tar.xz" ) ) )
|
|
||||||
$type = substr( $result, -6 );
|
|
||||||
elseif( substr( $result, -8 ) == ".tar.bz2" )
|
|
||||||
$type = "tar.bz2";
|
|
||||||
else
|
|
||||||
$type = substr( strrchr( $result, "." ), 1 );
|
|
||||||
$item["icon"] = $this->getTypeIcon( $type );
|
|
||||||
$item["ext"] = strtolower($type);
|
|
||||||
}
|
|
||||||
if( $this->config['showlastmodified'] == 1 ) { $item["lastmodified"] = date( "d.m.Y, G:i e", filemtime( $result ) ); }
|
|
||||||
if( $this->config['showfilesize'] == 1 ) {
|
|
||||||
$item["size"] = filesize( $result );
|
|
||||||
if( $item["size"] > 1073741824 ) $item["size"] = round( ( $item["size"]/1073741824 ), 2 ) . " GB";
|
|
||||||
elseif($item["size"]>1048576)$item["size"] = round( ( $item["size"]/1048576 ), 2 ) . " MB";
|
|
||||||
elseif($item["size"]>1024)$item["size"] = round( ( $item["size"]/1024 ), 2 ) . " KB";
|
|
||||||
else $item["size"] = $item["size"] . " Byte";
|
|
||||||
}
|
|
||||||
if( $this->config['showpermissions'] > 0 ) {
|
|
||||||
if( $this->config['showpermissions'] == 1 ) $item["fileperms"] = substr( decoct( fileperms( $result ) ), -3 );
|
|
||||||
elseif( $this->config['showpermissions'] == 2 ) $item["fileperms"] = $this->filePermsDecode( fileperms( $result ) );
|
|
||||||
if( $item["fileperms"] == "" ) $item["fileperms"] = " ";
|
|
||||||
$item["filepermmode"] = ( $this->config['showpermissions'] == 1 ) ? "short" : "long";
|
|
||||||
}
|
|
||||||
if( $this->config['showowner'] == 1 ) {
|
|
||||||
if ( function_exists( "posix_getpwuid" ) && fileowner($result) !== false ) {
|
|
||||||
$ownerarr = posix_getpwuid( fileowner( $result ) );
|
|
||||||
$item["owner"] = $ownerarr['name'];
|
|
||||||
} else $item["owner"] = false;
|
|
||||||
}
|
|
||||||
if( $this->config['showgroup'] == 1 ) {
|
|
||||||
if( function_exists( "posix_getgrgid" ) && filegroup( $result ) !== false ) {
|
|
||||||
$grouparr = posix_getgrgid( filegroup( $result ) );
|
|
||||||
$item["group"] = $grouparr['name'];
|
|
||||||
} else $item["group"] = false;
|
|
||||||
}
|
|
||||||
if( is_dir( $result ) ) $dirs[] = $item;
|
|
||||||
else $files[] = $item;
|
else $files[] = $item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2309,6 +2266,55 @@ function IFM( params ) {
|
|||||||
echo json_encode( array_merge( $dirs, $files ) );
|
echo json_encode( array_merge( $dirs, $files ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getItemInformation( $name ) {
|
||||||
|
$item = array();
|
||||||
|
$item["name"] = $name;
|
||||||
|
if( is_dir( $name ) ) {
|
||||||
|
$item["type"] = "dir";
|
||||||
|
if( $name == ".." )
|
||||||
|
$item["icon"] = "icon icon-up-open";
|
||||||
|
else
|
||||||
|
$item["icon"] = "icon icon-folder-empty";
|
||||||
|
} else {
|
||||||
|
$item["type"] = "file";
|
||||||
|
if( in_array( substr( $name, -7 ), array( ".tar.gz", ".tar.xz" ) ) )
|
||||||
|
$type = substr( $name, -6 );
|
||||||
|
elseif( substr( $name, -8 ) == ".tar.bz2" )
|
||||||
|
$type = "tar.bz2";
|
||||||
|
else
|
||||||
|
$type = substr( strrchr( $name, "." ), 1 );
|
||||||
|
$item["icon"] = $this->getTypeIcon( $type );
|
||||||
|
$item["ext"] = strtolower($type);
|
||||||
|
}
|
||||||
|
if( $this->config['showlastmodified'] == 1 ) { $item["lastmodified"] = date( "d.m.Y, G:i e", filemtime( $name ) ); }
|
||||||
|
if( $this->config['showfilesize'] == 1 ) {
|
||||||
|
$item["size"] = filesize( $name );
|
||||||
|
if( $item["size"] > 1073741824 ) $item["size"] = round( ( $item["size"]/1073741824 ), 2 ) . " GB";
|
||||||
|
elseif($item["size"]>1048576)$item["size"] = round( ( $item["size"]/1048576 ), 2 ) . " MB";
|
||||||
|
elseif($item["size"]>1024)$item["size"] = round( ( $item["size"]/1024 ), 2 ) . " KB";
|
||||||
|
else $item["size"] = $item["size"] . " Byte";
|
||||||
|
}
|
||||||
|
if( $this->config['showpermissions'] > 0 ) {
|
||||||
|
if( $this->config['showpermissions'] == 1 ) $item["fileperms"] = substr( decoct( fileperms( $name ) ), -3 );
|
||||||
|
elseif( $this->config['showpermissions'] == 2 ) $item["fileperms"] = $this->filePermsDecode( fileperms( $name ) );
|
||||||
|
if( $item["fileperms"] == "" ) $item["fileperms"] = " ";
|
||||||
|
$item["filepermmode"] = ( $this->config['showpermissions'] == 1 ) ? "short" : "long";
|
||||||
|
}
|
||||||
|
if( $this->config['showowner'] == 1 ) {
|
||||||
|
if ( function_exists( "posix_getpwuid" ) && fileowner($name) !== false ) {
|
||||||
|
$ownerarr = posix_getpwuid( fileowner( $name ) );
|
||||||
|
$item["owner"] = $ownerarr['name'];
|
||||||
|
} else $item["owner"] = false;
|
||||||
|
}
|
||||||
|
if( $this->config['showgroup'] == 1 ) {
|
||||||
|
if( function_exists( "posix_getgrgid" ) && filegroup( $name ) !== false ) {
|
||||||
|
$grouparr = posix_getgrgid( filegroup( $name ) );
|
||||||
|
$item["group"] = $grouparr['name'];
|
||||||
|
} else $item["group"] = false;
|
||||||
|
}
|
||||||
|
return $item;
|
||||||
|
}
|
||||||
|
|
||||||
private function getConfig() {
|
private function getConfig() {
|
||||||
$ret = $this->config;
|
$ret = $this->config;
|
||||||
$ret['inline'] = ( $this->mode == "inline" ) ? true : false;
|
$ret['inline'] = ( $this->mode == "inline" ) ? true : false;
|
||||||
@@ -2345,6 +2351,28 @@ function IFM( params ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function searchItems( $d ) {
|
||||||
|
$this->chDirIfNecessary( $d['dir'] );
|
||||||
|
try {
|
||||||
|
$results = $this->searchItemsRecursive( $d['pattern'] );
|
||||||
|
echo json_encode( $results );
|
||||||
|
} catch( Exception $e ) {
|
||||||
|
echo json_encode( array( "status" => "ERROR", "message" => $e->getMessage() ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function searchItemsRecursive( $pattern, $dir="" ) {
|
||||||
|
$items = array();
|
||||||
|
$dir = $dir ? $dir : '.';
|
||||||
|
foreach( glob( $this->pathCombine( $dir, $pattern ) ) as $result ) {
|
||||||
|
array_push( $items, $this->getItemInformation( $result ) );
|
||||||
|
}
|
||||||
|
foreach( glob( $this->pathCombine( $dir, '*') , GLOB_ONLYDIR ) as $subdir ) {
|
||||||
|
$items = array_merge( $items, $this->searchItemsRecursive( $pattern, $subdir ) );
|
||||||
|
}
|
||||||
|
return $items;
|
||||||
|
}
|
||||||
|
|
||||||
private function getFolderTree( $d ) {
|
private function getFolderTree( $d ) {
|
||||||
echo json_encode(
|
echo json_encode(
|
||||||
array_merge(
|
array_merge(
|
||||||
|
120
ifm.php
120
ifm.php
@@ -2206,6 +2206,7 @@ function IFM( params ) {
|
|||||||
case "zipnload": $this->zipnload( $_REQUEST); break;
|
case "zipnload": $this->zipnload( $_REQUEST); break;
|
||||||
case "remoteUpload": $this->remoteUpload( $_REQUEST ); break;
|
case "remoteUpload": $this->remoteUpload( $_REQUEST ); break;
|
||||||
case "multidelete": $this->deleteMultipleFiles( $_REQUEST ); break;
|
case "multidelete": $this->deleteMultipleFiles( $_REQUEST ); break;
|
||||||
|
case "searchItems": $this->searchItems( $_REQUEST ); break;
|
||||||
case "getFolderTree": $this->getFolderTree( $_REQUEST ); break;
|
case "getFolderTree": $this->getFolderTree( $_REQUEST ); break;
|
||||||
default:
|
default:
|
||||||
echo json_encode( array( "status" => "ERROR", "message" => "Invalid api action given" ) );
|
echo json_encode( array( "status" => "ERROR", "message" => "Invalid api action given" ) );
|
||||||
@@ -2253,52 +2254,8 @@ function IFM( params ) {
|
|||||||
elseif( $result == "." ) {}
|
elseif( $result == "." ) {}
|
||||||
elseif( $result != ".." && substr( $result, 0, 1 ) == "." && $this->config['showhiddenfiles'] != 1 ) {}
|
elseif( $result != ".." && substr( $result, 0, 1 ) == "." && $this->config['showhiddenfiles'] != 1 ) {}
|
||||||
else {
|
else {
|
||||||
$item = array();
|
$item = $this->getItemInformation( $result );
|
||||||
$item["name"] = $result;
|
if( $item['type'] == "dir" ) $dirs[] = $item;
|
||||||
if( is_dir( $result ) ) {
|
|
||||||
$item["type"] = "dir";
|
|
||||||
if( $result == ".." )
|
|
||||||
$item["icon"] = "icon icon-up-open";
|
|
||||||
else
|
|
||||||
$item["icon"] = "icon icon-folder-empty";
|
|
||||||
} else {
|
|
||||||
$item["type"] = "file";
|
|
||||||
if( in_array( substr( $result, -7 ), array( ".tar.gz", ".tar.xz" ) ) )
|
|
||||||
$type = substr( $result, -6 );
|
|
||||||
elseif( substr( $result, -8 ) == ".tar.bz2" )
|
|
||||||
$type = "tar.bz2";
|
|
||||||
else
|
|
||||||
$type = substr( strrchr( $result, "." ), 1 );
|
|
||||||
$item["icon"] = $this->getTypeIcon( $type );
|
|
||||||
$item["ext"] = strtolower($type);
|
|
||||||
}
|
|
||||||
if( $this->config['showlastmodified'] == 1 ) { $item["lastmodified"] = date( "d.m.Y, G:i e", filemtime( $result ) ); }
|
|
||||||
if( $this->config['showfilesize'] == 1 ) {
|
|
||||||
$item["size"] = filesize( $result );
|
|
||||||
if( $item["size"] > 1073741824 ) $item["size"] = round( ( $item["size"]/1073741824 ), 2 ) . " GB";
|
|
||||||
elseif($item["size"]>1048576)$item["size"] = round( ( $item["size"]/1048576 ), 2 ) . " MB";
|
|
||||||
elseif($item["size"]>1024)$item["size"] = round( ( $item["size"]/1024 ), 2 ) . " KB";
|
|
||||||
else $item["size"] = $item["size"] . " Byte";
|
|
||||||
}
|
|
||||||
if( $this->config['showpermissions'] > 0 ) {
|
|
||||||
if( $this->config['showpermissions'] == 1 ) $item["fileperms"] = substr( decoct( fileperms( $result ) ), -3 );
|
|
||||||
elseif( $this->config['showpermissions'] == 2 ) $item["fileperms"] = $this->filePermsDecode( fileperms( $result ) );
|
|
||||||
if( $item["fileperms"] == "" ) $item["fileperms"] = " ";
|
|
||||||
$item["filepermmode"] = ( $this->config['showpermissions'] == 1 ) ? "short" : "long";
|
|
||||||
}
|
|
||||||
if( $this->config['showowner'] == 1 ) {
|
|
||||||
if ( function_exists( "posix_getpwuid" ) && fileowner($result) !== false ) {
|
|
||||||
$ownerarr = posix_getpwuid( fileowner( $result ) );
|
|
||||||
$item["owner"] = $ownerarr['name'];
|
|
||||||
} else $item["owner"] = false;
|
|
||||||
}
|
|
||||||
if( $this->config['showgroup'] == 1 ) {
|
|
||||||
if( function_exists( "posix_getgrgid" ) && filegroup( $result ) !== false ) {
|
|
||||||
$grouparr = posix_getgrgid( filegroup( $result ) );
|
|
||||||
$item["group"] = $grouparr['name'];
|
|
||||||
} else $item["group"] = false;
|
|
||||||
}
|
|
||||||
if( is_dir( $result ) ) $dirs[] = $item;
|
|
||||||
else $files[] = $item;
|
else $files[] = $item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2309,6 +2266,55 @@ function IFM( params ) {
|
|||||||
echo json_encode( array_merge( $dirs, $files ) );
|
echo json_encode( array_merge( $dirs, $files ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getItemInformation( $name ) {
|
||||||
|
$item = array();
|
||||||
|
$item["name"] = $name;
|
||||||
|
if( is_dir( $name ) ) {
|
||||||
|
$item["type"] = "dir";
|
||||||
|
if( $name == ".." )
|
||||||
|
$item["icon"] = "icon icon-up-open";
|
||||||
|
else
|
||||||
|
$item["icon"] = "icon icon-folder-empty";
|
||||||
|
} else {
|
||||||
|
$item["type"] = "file";
|
||||||
|
if( in_array( substr( $name, -7 ), array( ".tar.gz", ".tar.xz" ) ) )
|
||||||
|
$type = substr( $name, -6 );
|
||||||
|
elseif( substr( $name, -8 ) == ".tar.bz2" )
|
||||||
|
$type = "tar.bz2";
|
||||||
|
else
|
||||||
|
$type = substr( strrchr( $name, "." ), 1 );
|
||||||
|
$item["icon"] = $this->getTypeIcon( $type );
|
||||||
|
$item["ext"] = strtolower($type);
|
||||||
|
}
|
||||||
|
if( $this->config['showlastmodified'] == 1 ) { $item["lastmodified"] = date( "d.m.Y, G:i e", filemtime( $name ) ); }
|
||||||
|
if( $this->config['showfilesize'] == 1 ) {
|
||||||
|
$item["size"] = filesize( $name );
|
||||||
|
if( $item["size"] > 1073741824 ) $item["size"] = round( ( $item["size"]/1073741824 ), 2 ) . " GB";
|
||||||
|
elseif($item["size"]>1048576)$item["size"] = round( ( $item["size"]/1048576 ), 2 ) . " MB";
|
||||||
|
elseif($item["size"]>1024)$item["size"] = round( ( $item["size"]/1024 ), 2 ) . " KB";
|
||||||
|
else $item["size"] = $item["size"] . " Byte";
|
||||||
|
}
|
||||||
|
if( $this->config['showpermissions'] > 0 ) {
|
||||||
|
if( $this->config['showpermissions'] == 1 ) $item["fileperms"] = substr( decoct( fileperms( $name ) ), -3 );
|
||||||
|
elseif( $this->config['showpermissions'] == 2 ) $item["fileperms"] = $this->filePermsDecode( fileperms( $name ) );
|
||||||
|
if( $item["fileperms"] == "" ) $item["fileperms"] = " ";
|
||||||
|
$item["filepermmode"] = ( $this->config['showpermissions'] == 1 ) ? "short" : "long";
|
||||||
|
}
|
||||||
|
if( $this->config['showowner'] == 1 ) {
|
||||||
|
if ( function_exists( "posix_getpwuid" ) && fileowner($name) !== false ) {
|
||||||
|
$ownerarr = posix_getpwuid( fileowner( $name ) );
|
||||||
|
$item["owner"] = $ownerarr['name'];
|
||||||
|
} else $item["owner"] = false;
|
||||||
|
}
|
||||||
|
if( $this->config['showgroup'] == 1 ) {
|
||||||
|
if( function_exists( "posix_getgrgid" ) && filegroup( $name ) !== false ) {
|
||||||
|
$grouparr = posix_getgrgid( filegroup( $name ) );
|
||||||
|
$item["group"] = $grouparr['name'];
|
||||||
|
} else $item["group"] = false;
|
||||||
|
}
|
||||||
|
return $item;
|
||||||
|
}
|
||||||
|
|
||||||
private function getConfig() {
|
private function getConfig() {
|
||||||
$ret = $this->config;
|
$ret = $this->config;
|
||||||
$ret['inline'] = ( $this->mode == "inline" ) ? true : false;
|
$ret['inline'] = ( $this->mode == "inline" ) ? true : false;
|
||||||
@@ -2345,6 +2351,28 @@ function IFM( params ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function searchItems( $d ) {
|
||||||
|
$this->chDirIfNecessary( $d['dir'] );
|
||||||
|
try {
|
||||||
|
$results = $this->searchItemsRecursive( $d['pattern'] );
|
||||||
|
echo json_encode( $results );
|
||||||
|
} catch( Exception $e ) {
|
||||||
|
echo json_encode( array( "status" => "ERROR", "message" => $e->getMessage() ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function searchItemsRecursive( $pattern, $dir="" ) {
|
||||||
|
$items = array();
|
||||||
|
$dir = $dir ? $dir : '.';
|
||||||
|
foreach( glob( $this->pathCombine( $dir, $pattern ) ) as $result ) {
|
||||||
|
array_push( $items, $this->getItemInformation( $result ) );
|
||||||
|
}
|
||||||
|
foreach( glob( $this->pathCombine( $dir, '*') , GLOB_ONLYDIR ) as $subdir ) {
|
||||||
|
$items = array_merge( $items, $this->searchItemsRecursive( $pattern, $subdir ) );
|
||||||
|
}
|
||||||
|
return $items;
|
||||||
|
}
|
||||||
|
|
||||||
private function getFolderTree( $d ) {
|
private function getFolderTree( $d ) {
|
||||||
echo json_encode(
|
echo json_encode(
|
||||||
array_merge(
|
array_merge(
|
||||||
|
124
src/main.php
124
src/main.php
@@ -243,6 +243,7 @@ f00bar;
|
|||||||
case "zipnload": $this->zipnload( $_REQUEST); break;
|
case "zipnload": $this->zipnload( $_REQUEST); break;
|
||||||
case "remoteUpload": $this->remoteUpload( $_REQUEST ); break;
|
case "remoteUpload": $this->remoteUpload( $_REQUEST ); break;
|
||||||
case "multidelete": $this->deleteMultipleFiles( $_REQUEST ); break;
|
case "multidelete": $this->deleteMultipleFiles( $_REQUEST ); break;
|
||||||
|
case "searchItems": $this->searchItems( $_REQUEST ); break;
|
||||||
case "getFolderTree": $this->getFolderTree( $_REQUEST ); break;
|
case "getFolderTree": $this->getFolderTree( $_REQUEST ); break;
|
||||||
default:
|
default:
|
||||||
echo json_encode( array( "status" => "ERROR", "message" => "Invalid api action given" ) );
|
echo json_encode( array( "status" => "ERROR", "message" => "Invalid api action given" ) );
|
||||||
@@ -290,52 +291,8 @@ f00bar;
|
|||||||
elseif( $result == "." ) {}
|
elseif( $result == "." ) {}
|
||||||
elseif( $result != ".." && substr( $result, 0, 1 ) == "." && $this->config['showhiddenfiles'] != 1 ) {}
|
elseif( $result != ".." && substr( $result, 0, 1 ) == "." && $this->config['showhiddenfiles'] != 1 ) {}
|
||||||
else {
|
else {
|
||||||
$item = array();
|
$item = $this->getItemInformation( $result );
|
||||||
$item["name"] = $result;
|
if( $item['type'] == "dir" ) $dirs[] = $item;
|
||||||
if( is_dir( $result ) ) {
|
|
||||||
$item["type"] = "dir";
|
|
||||||
if( $result == ".." )
|
|
||||||
$item["icon"] = "icon icon-up-open";
|
|
||||||
else
|
|
||||||
$item["icon"] = "icon icon-folder-empty";
|
|
||||||
} else {
|
|
||||||
$item["type"] = "file";
|
|
||||||
if( in_array( substr( $result, -7 ), array( ".tar.gz", ".tar.xz" ) ) )
|
|
||||||
$type = substr( $result, -6 );
|
|
||||||
elseif( substr( $result, -8 ) == ".tar.bz2" )
|
|
||||||
$type = "tar.bz2";
|
|
||||||
else
|
|
||||||
$type = substr( strrchr( $result, "." ), 1 );
|
|
||||||
$item["icon"] = $this->getTypeIcon( $type );
|
|
||||||
$item["ext"] = strtolower($type);
|
|
||||||
}
|
|
||||||
if( $this->config['showlastmodified'] == 1 ) { $item["lastmodified"] = date( "d.m.Y, G:i e", filemtime( $result ) ); }
|
|
||||||
if( $this->config['showfilesize'] == 1 ) {
|
|
||||||
$item["size"] = filesize( $result );
|
|
||||||
if( $item["size"] > 1073741824 ) $item["size"] = round( ( $item["size"]/1073741824 ), 2 ) . " GB";
|
|
||||||
elseif($item["size"]>1048576)$item["size"] = round( ( $item["size"]/1048576 ), 2 ) . " MB";
|
|
||||||
elseif($item["size"]>1024)$item["size"] = round( ( $item["size"]/1024 ), 2 ) . " KB";
|
|
||||||
else $item["size"] = $item["size"] . " Byte";
|
|
||||||
}
|
|
||||||
if( $this->config['showpermissions'] > 0 ) {
|
|
||||||
if( $this->config['showpermissions'] == 1 ) $item["fileperms"] = substr( decoct( fileperms( $result ) ), -3 );
|
|
||||||
elseif( $this->config['showpermissions'] == 2 ) $item["fileperms"] = $this->filePermsDecode( fileperms( $result ) );
|
|
||||||
if( $item["fileperms"] == "" ) $item["fileperms"] = " ";
|
|
||||||
$item["filepermmode"] = ( $this->config['showpermissions'] == 1 ) ? "short" : "long";
|
|
||||||
}
|
|
||||||
if( $this->config['showowner'] == 1 ) {
|
|
||||||
if ( function_exists( "posix_getpwuid" ) && fileowner($result) !== false ) {
|
|
||||||
$ownerarr = posix_getpwuid( fileowner( $result ) );
|
|
||||||
$item["owner"] = $ownerarr['name'];
|
|
||||||
} else $item["owner"] = false;
|
|
||||||
}
|
|
||||||
if( $this->config['showgroup'] == 1 ) {
|
|
||||||
if( function_exists( "posix_getgrgid" ) && filegroup( $result ) !== false ) {
|
|
||||||
$grouparr = posix_getgrgid( filegroup( $result ) );
|
|
||||||
$item["group"] = $grouparr['name'];
|
|
||||||
} else $item["group"] = false;
|
|
||||||
}
|
|
||||||
if( is_dir( $result ) ) $dirs[] = $item;
|
|
||||||
else $files[] = $item;
|
else $files[] = $item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -346,6 +303,55 @@ f00bar;
|
|||||||
echo json_encode( array_merge( $dirs, $files ) );
|
echo json_encode( array_merge( $dirs, $files ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getItemInformation( $name ) {
|
||||||
|
$item = array();
|
||||||
|
$item["name"] = $name;
|
||||||
|
if( is_dir( $name ) ) {
|
||||||
|
$item["type"] = "dir";
|
||||||
|
if( $name == ".." )
|
||||||
|
$item["icon"] = "icon icon-up-open";
|
||||||
|
else
|
||||||
|
$item["icon"] = "icon icon-folder-empty";
|
||||||
|
} else {
|
||||||
|
$item["type"] = "file";
|
||||||
|
if( in_array( substr( $name, -7 ), array( ".tar.gz", ".tar.xz" ) ) )
|
||||||
|
$type = substr( $name, -6 );
|
||||||
|
elseif( substr( $name, -8 ) == ".tar.bz2" )
|
||||||
|
$type = "tar.bz2";
|
||||||
|
else
|
||||||
|
$type = substr( strrchr( $name, "." ), 1 );
|
||||||
|
$item["icon"] = $this->getTypeIcon( $type );
|
||||||
|
$item["ext"] = strtolower($type);
|
||||||
|
}
|
||||||
|
if( $this->config['showlastmodified'] == 1 ) { $item["lastmodified"] = date( "d.m.Y, G:i e", filemtime( $name ) ); }
|
||||||
|
if( $this->config['showfilesize'] == 1 ) {
|
||||||
|
$item["size"] = filesize( $name );
|
||||||
|
if( $item["size"] > 1073741824 ) $item["size"] = round( ( $item["size"]/1073741824 ), 2 ) . " GB";
|
||||||
|
elseif($item["size"]>1048576)$item["size"] = round( ( $item["size"]/1048576 ), 2 ) . " MB";
|
||||||
|
elseif($item["size"]>1024)$item["size"] = round( ( $item["size"]/1024 ), 2 ) . " KB";
|
||||||
|
else $item["size"] = $item["size"] . " Byte";
|
||||||
|
}
|
||||||
|
if( $this->config['showpermissions'] > 0 ) {
|
||||||
|
if( $this->config['showpermissions'] == 1 ) $item["fileperms"] = substr( decoct( fileperms( $name ) ), -3 );
|
||||||
|
elseif( $this->config['showpermissions'] == 2 ) $item["fileperms"] = $this->filePermsDecode( fileperms( $name ) );
|
||||||
|
if( $item["fileperms"] == "" ) $item["fileperms"] = " ";
|
||||||
|
$item["filepermmode"] = ( $this->config['showpermissions'] == 1 ) ? "short" : "long";
|
||||||
|
}
|
||||||
|
if( $this->config['showowner'] == 1 ) {
|
||||||
|
if ( function_exists( "posix_getpwuid" ) && fileowner($name) !== false ) {
|
||||||
|
$ownerarr = posix_getpwuid( fileowner( $name ) );
|
||||||
|
$item["owner"] = $ownerarr['name'];
|
||||||
|
} else $item["owner"] = false;
|
||||||
|
}
|
||||||
|
if( $this->config['showgroup'] == 1 ) {
|
||||||
|
if( function_exists( "posix_getgrgid" ) && filegroup( $name ) !== false ) {
|
||||||
|
$grouparr = posix_getgrgid( filegroup( $name ) );
|
||||||
|
$item["group"] = $grouparr['name'];
|
||||||
|
} else $item["group"] = false;
|
||||||
|
}
|
||||||
|
return $item;
|
||||||
|
}
|
||||||
|
|
||||||
private function getConfig() {
|
private function getConfig() {
|
||||||
$ret = $this->config;
|
$ret = $this->config;
|
||||||
$ret['inline'] = ( $this->mode == "inline" ) ? true : false;
|
$ret['inline'] = ( $this->mode == "inline" ) ? true : false;
|
||||||
@@ -382,6 +388,32 @@ f00bar;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function searchItems( $d ) {
|
||||||
|
$this->chDirIfNecessary( $d['dir'] );
|
||||||
|
if( strpos( $d['pattern'], '/' ) !== false ) {
|
||||||
|
echo json_decode( array( "status" => "ERROR", "message" => "Pattern must not contain slashes" ) );
|
||||||
|
exit( 1 );
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
$results = $this->searchItemsRecursive( $d['pattern'] );
|
||||||
|
echo json_encode( $results );
|
||||||
|
} catch( Exception $e ) {
|
||||||
|
echo json_encode( array( "status" => "ERROR", "message" => $e->getMessage() ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function searchItemsRecursive( $pattern, $dir="" ) {
|
||||||
|
$items = array();
|
||||||
|
$dir = $dir ? $dir : '.';
|
||||||
|
foreach( glob( $this->pathCombine( $dir, $pattern ) ) as $result ) {
|
||||||
|
array_push( $items, $this->getItemInformation( $result ) );
|
||||||
|
}
|
||||||
|
foreach( glob( $this->pathCombine( $dir, '*') , GLOB_ONLYDIR ) as $subdir ) {
|
||||||
|
$items = array_merge( $items, $this->searchItemsRecursive( $pattern, $subdir ) );
|
||||||
|
}
|
||||||
|
return $items;
|
||||||
|
}
|
||||||
|
|
||||||
private function getFolderTree( $d ) {
|
private function getFolderTree( $d ) {
|
||||||
echo json_encode(
|
echo json_encode(
|
||||||
array_merge(
|
array_merge(
|
||||||
|
Reference in New Issue
Block a user