Hi,
I've made a couple of changes to my version of FCKeditor. I'm using gallery (gallery.sourceforge.net), and I wanted the Image browser to display the files in the photoalbum directory. There can be many files in each directory - gallery generates a mid-sized and thumbnail image for each file that is uploaded, and it made sense to display these together, i.e. sort the file & folder names alphabetically. I also only wanted to display image files (.jpg, .gif and .png), and not the setup files that gallery adds to each directory.
I made the following changes to connector.php:
***REPLACE***
while ( $sFile = readdir( $oCurrentFolder ) )
{
if ( $sFile != '.' && $sFile != '..' )
{
if ( is_dir( $sServerDir . $sFile ) )
$sFolders .= '<Folder name="' . $sFile . '" />' ;
else
{
$iFileSize = filesize( $sServerDir . $sFile ) ;
if ( $iFileSize > 0 )
{
$iFileSize = round( $iFileSize / 1024 ) ;
if ( $iFileSize < 1 ) $iFileSize = 1 ;
}
$sFiles .= '<File name="' . $sFile . '" size="' . $iFileSize . '" />' ;
}
}
}
***REPLACE WITH***
while ( $sFile = readdir( $oCurrentFolder ) )
{
if ( $sFile != '.' && $sFile != '..' )
{
if ( is_dir( $sServerDir . $sFile ) )
$sFoldersArr[] = '<Folder name="' . $sFile . '" />' ;
else if (ereg('.jpg|.gif|.png', $sFile)) //gareth mod to only display image files
{
$iFileSize = filesize( $sServerDir . $sFile ) ;
if ( $iFileSize > 0 )
{
$iFileSize = round( $iFileSize / 1024 ) ;
if ( $iFileSize < 1 ) $iFileSize = 1 ;
}
$sFilesArr[] = '<File name="' . $sFile . '" size="' . $iFileSize . '" />' ;
}
}
}
if (count($sFilesArr) > 0)
{
asort($sFilesArr);
foreach ($sFilesArr as $File)
$sFiles .= $File;
}
if (count($sFoldersArr) > 0)
{
asort($sFoldersArr);
foreach ($sFoldersArr as $Folder)
$sFolders .= $Folder;
}
Would appreciate if anyone had any comments / better ways of achieving this. There's probably a function that I've missed already built-in for this.
I've made a couple of changes to my version of FCKeditor. I'm using gallery (gallery.sourceforge.net), and I wanted the Image browser to display the files in the photoalbum directory. There can be many files in each directory - gallery generates a mid-sized and thumbnail image for each file that is uploaded, and it made sense to display these together, i.e. sort the file & folder names alphabetically. I also only wanted to display image files (.jpg, .gif and .png), and not the setup files that gallery adds to each directory.
I made the following changes to connector.php:
***REPLACE***
while ( $sFile = readdir( $oCurrentFolder ) )
{
if ( $sFile != '.' && $sFile != '..' )
{
if ( is_dir( $sServerDir . $sFile ) )
$sFolders .= '<Folder name="' . $sFile . '" />' ;
else
{
$iFileSize = filesize( $sServerDir . $sFile ) ;
if ( $iFileSize > 0 )
{
$iFileSize = round( $iFileSize / 1024 ) ;
if ( $iFileSize < 1 ) $iFileSize = 1 ;
}
$sFiles .= '<File name="' . $sFile . '" size="' . $iFileSize . '" />' ;
}
}
}
***REPLACE WITH***
while ( $sFile = readdir( $oCurrentFolder ) )
{
if ( $sFile != '.' && $sFile != '..' )
{
if ( is_dir( $sServerDir . $sFile ) )
$sFoldersArr[] = '<Folder name="' . $sFile . '" />' ;
else if (ereg('.jpg|.gif|.png', $sFile)) //gareth mod to only display image files
{
$iFileSize = filesize( $sServerDir . $sFile ) ;
if ( $iFileSize > 0 )
{
$iFileSize = round( $iFileSize / 1024 ) ;
if ( $iFileSize < 1 ) $iFileSize = 1 ;
}
$sFilesArr[] = '<File name="' . $sFile . '" size="' . $iFileSize . '" />' ;
}
}
}
if (count($sFilesArr) > 0)
{
asort($sFilesArr);
foreach ($sFilesArr as $File)
$sFiles .= $File;
}
if (count($sFoldersArr) > 0)
{
asort($sFoldersArr);
foreach ($sFoldersArr as $Folder)
$sFolders .= $Folder;
}
Would appreciate if anyone had any comments / better ways of achieving this. There's probably a function that I've missed already built-in for this.
RE: Display Only Image Files & Alphabetically
If you're going to try sorting, I dont know if the connector can handle this automatically...
If it cant, I'd suggest reading into an array like you have done and then looking for a "bubble sort" function for arrays in PHP
I'm an ASP man myself, so I'd load the content into a recordset or dictionary object and just run the internal sort commands...
M$ may be awful, but they do have some handy functions
Stu