Page 1 of 1

How to use filebrowser with a plugin

Posted: Mon Apr 02, 2018 3:03 pm
by Tata
How to integrate/use the standard filebrowser in a plugin? There are plugins using files (images, media, documents) stored in /userfiles. Mostly the admin must write the files directly into the input fields withing the plugin configuration. Much more comfortable would be to have the fields linked to filebrowser and simply click the desired files. Not seldom a typo results in errors. This way any typo would be avoided.

Re: How to use filebrowser with a plugin

Posted: Mon Apr 02, 2018 3:27 pm
by cmb
Tata wrote:
Mon Apr 02, 2018 3:03 pm
How to integrate/use the standard filebrowser in a plugin? There are plugins using files (images, media, documents) stored in /userfiles. Mostly the admin must write the files directly into the input fields withing the plugin configuration. Much more comfortable would be to have the fields linked to filebrowser and simply click the desired files. Not seldom a typo results in errors. This way any typo would be avoided.
Generally, I would suggest to change these plugins, so that they do not allow arbitrary files, but rather care about the images in a single folder only, and possibly offer these in <select> elements.

That said, it is possible to integrate the filebrowser: see viewtopic.php?f=12&t=8636 for details.

Re: How to use filebrowser with a plugin

Posted: Mon Apr 02, 2018 8:12 pm
by Tata
Would there be a way to rewrite the filemanager as an integrable plugin?
I mean, having it both as the core plugin and as a function usable within another plugins. I think this would help all authors and would make all plugins some way unified in terms of handling files.
However, for the use with plugins, there shall be in respective config.phps specified the folder/file types with which the filemanager-function should communicate.
E.g. in xzy_plugin
in config.php

Code: Select all

...
$plugin_cf['xyz']['files_folder']="userfiles/images/xyz";
$plugin_cf['xyz']['files_type']="jpg,png,svg";
...

Re: How to use filebrowser with a plugin

Posted: Mon Apr 02, 2018 10:19 pm
by cmb
Tata wrote:
Mon Apr 02, 2018 8:12 pm
Would there be a way to rewrite the filemanager as an integrable plugin?
It is already.
Tata wrote:
Mon Apr 02, 2018 8:12 pm
I mean, having it both as the core plugin and as a function usable within another plugins.
It's not that simple, unfortunately. A single PHP function doesn't appear to be sufficient to specify the non-trivial interaction; at the very least there has to be some JavaScript which actually processes the filebrowser's input. Add to this that we're trying to support different file managers as smoothly as possible. That's presumably the most important reason why the filebrowser integration API is as complex as it is (a probably minor one is that it has been developed with PHP 4 compatibility in mind, so class autoloading and Interfaces were no option).

Anyhow, as I said before: it's probably best not to offer <input type="text"> elements for file selection in plugins, but rather <select> elements which present all available (and suitable) images in a certain folder. In my opinion, that's quite suitable. There may be even better alternatives. Think out of the box! :)