How to use filebrowser with a plugin

Discussions and requests related to new CMSimple features, plugins, templates etc. and how to develop.
Please don't ask for support at this forums!
Post Reply
Tata
Posts: 2716
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

How to use filebrowser with a plugin

Post by Tata » 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.
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.

cmb
Posts: 12663
Joined: Tue Jun 21, 2011 11:04 am
Location: Mü-Sa, RLP, DE
Contact:

Re: How to use filebrowser with a plugin

Post by cmb » Mon Apr 02, 2018 3:27 pm

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.
Christoph M. Becker –Plugins for CMSimple_XH, but not for CMSimple 4+

Tata
Posts: 2716
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

Re: How to use filebrowser with a plugin

Post by Tata » Mon Apr 02, 2018 8:12 pm

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";
...
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.

cmb
Posts: 12663
Joined: Tue Jun 21, 2011 11:04 am
Location: Mü-Sa, RLP, DE
Contact:

Re: How to use filebrowser with a plugin

Post by cmb » Mon Apr 02, 2018 10:19 pm

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! :)
Christoph M. Becker –Plugins for CMSimple_XH, but not for CMSimple 4+

Post Reply