Elfinder: Display different icon for empty folder

Created on 18 Mar 2020  路  5Comments  路  Source: Studio-42/elFinder

Hello all !

like here : https://github.com/Studio-42/elFinder/issues/1643

but my code :

static public function connectorAction(kore_route_route $route)
    {
        self::_initFromRoute($route);

        require __DIR__.'/../../public/vendors/elfinder/vendor/autoload.php';

        // Enable FTP connector netmount
        //elFinder::$netDrivers['ftp'] = 'FTP';
        // ===============================================

        $user = user_account::getCurrentUser();

        if($user->dropbox_appkey and $user->dropbox_appsecret) {
            // Required for Dropbox network mount
            // Installation by composer
            // `composer require kunalvarma05/dropbox-php-sdk`
            // Enable network mount
            elFinder::$netDrivers['dropbox2'] = 'Dropbox2';
            // Dropbox2 Netmount driver need next two settings. You can get at https://www.dropbox.com/developers/apps
            // AND reuire regist redirect url to "YOUR_CONNECTOR_URL?cmd=netmount&protocol=dropbox2&host=1"
            define('ELFINDER_DROPBOX_APPKEY',    $user->dropbox_appkey);
            define('ELFINDER_DROPBOX_APPSECRET', $user->dropbox_appsecret);
        }

        /**
         * Simple function to demonstrate how to control file access using "accessControl" callback.
         * This method will disable accessing files/folders starting from '.' (dot)
         *
         * @param  string  $attr  attribute name (read|write|locked|hidden)
         * @param  string  $path  file path relative to volume root directory started with directory separator
         * @return bool|null
         **/
        function access($attr, $path, $data, $volume) {
            return strpos(basename($path), '.') === 0       // if file/folder begins with '.' (dot)
            ? !($attr == 'read' || $attr == 'write')    // set read+write to false, other (locked+hidden) set to true
            :  null;                                    // else elFinder decide it itself
        }

        $startPath     = kore::$conf->uploadPath;
        $url = $user->getUploadDirName();

        /**
         * @param $cmd
         * @param $result
         * @param $args
         * @param $elfinder
         * @param $volume
         */
        function setEmptyFolderCssName($cmd, &$result, $args, $elfinder, $volume) {
            if ($volume && $volume instanceof elFinderVolumeLocalFileSystem && $result) {
                $key = '';
                if (! empty($result['files'])) {
                    $key = 'files';
                } else if (! empty($result['tree'])) {
                    $key = 'tree';
                } else if (! empty($result['added'])) {
                    $key = 'added';
                }
                if ($key) {
                    foreach($result[$key] as $i => $file) {
                        if (isset($file['mime']) && $file['mime'] === 'directory') {
                            $path = $volume->getPath($file['hash']);
                            if (($items = scandir($path)) && count($items) === 2) {
                                $result[$key][$i]['csscls'] = 'elfinder-dir-empty';
                            }
                        }
                    }
                }
            }
        }


        // Documentation for connector options:
        // https://github.com/Studio-42/elFinder/wiki/Connector-configuration-options
        $opts = array(
                // 'debug' => true,
                'roots' => array(
                        array(
                            'bind' => array( 'open tree parent mkdir' => array( 'setEmptyFolderCssName' ) ),
                            'driver'        => 'LocalFileSystem',           // driver for accessing file system (REQUIRED)
                            'path'          => $startPath,     // path to files (REQUIRED)
                            'URL'           => kore::$conf->webHost.'/upload/'.$url, // URL to files (REQUIRED)
                            'startPath'     => $startPath,
                            'dispInlineRegex' => ".*"
                        )
                )
        );

        // run elFinder
        $connector = new elFinderConnector(new elFinder($opts));
        $connector->run();
    }

elFinder work correctly but setEmptyFolderCssName do nothing ... :/ No CSS class & no other icon

Why ?

question

All 5 comments

@Ange7 Use the function definition by assigning it to a variable, or define it as a static class method and use it. That's the basics of PHP.

@nao-pon even with this code

$setEmptyFolderCssName = function($cmd, &$result, $args, $elfinder, $volume) {
            if ($volume && $volume instanceof elFinderVolumeLocalFileSystem && $result) {
                $key = '';
                if (! empty($result['files'])) {
                    $key = 'files';
                } else if (! empty($result['tree'])) {
                    $key = 'tree';
                } else if (! empty($result['added'])) {
                    $key = 'added';
                }
                if ($key) {
                    foreach($result[$key] as $i => $file) {
                        if (isset($file['mime']) && $file['mime'] === 'directory') {
                            $path = $volume->getPath($file['hash']);
                            if (($items = scandir($path)) && count($items) === 2) {
                                $result[$key][$i]['csscls'] = 'elfinder-dir-empty';
                            }
                        }
                    }
                }
            }
        };


        // Documentation for connector options:
        // https://github.com/Studio-42/elFinder/wiki/Connector-configuration-options
        $opts = array(
                // 'debug' => true,
                'roots' => array(
                        array(
                            'bind' => array( 'open tree parent mkdir' => array( $setEmptyFolderCssName ) ),
                            'driver'        => 'LocalFileSystem',           // driver for accessing file system (REQUIRED)
                            'path'          => $startPath,     // path to files (REQUIRED)
                            'URL'           => kore::$conf->webHost.'/upload/'.$url, // URL to files (REQUIRED)
                            'startPath'     => $startPath,
                            'dispInlineRegex' => ".*"
                        )
                )
        );

and not working...

if i try

'bind' => array( 'open tree parent mkdir' => $setEmptyFolderCssName ),

cause in elfinder class it seems that i don't need to set array($setEmptyFolderCssName)

But not working too

@Ange7 The 'bind' option is a main-level option, not a root option.

thank you @nao-pon

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kagagnon picture kagagnon  路  3Comments

shiyee picture shiyee  路  3Comments

ramin-gitt picture ramin-gitt  路  3Comments

CodeLyokoXtEAM picture CodeLyokoXtEAM  路  3Comments

JuanWilde picture JuanWilde  路  4Comments