XH 1.6: Different Kinds of Inputs for Config Forms

Discussions and requests related to new CMSimple features, plugins, templates etc. and how to develop.
Please don't ask for support at this forums!
cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

XH 1.6: Different Kinds of Inputs for Config Forms

Post by cmb » Mon Oct 01, 2012 9:51 pm

Hello Developers,

there was a quite large thread about this topic more than a year ago: http://cmsimpleforum.com/viewtopic.php?f=29&t=3224 -- unfortunately without any solution. In the meantime the topic popped up more than once [1], so IMO it's time to find and finally implement a solution. Please note that I'm not taking about the configuration of plugins only, but about the configuration of the core too.

In the past I've experimented with several solutions, but none of them would have been completely backward compatible. But now I figured out a solution, that should be easy to implement (for core and pluginloader), simple to use for plugin developers and that would work for older variants/versions of CMSimple and the pluginloader too.

The idea is having an additional file for each config.php that contains meta information about the entries. The file is necessary only to build and save the configuration form, so it will not hurt general performance. Of course it could be ignored completely -- by non-conforming variants/versions of CMSimple/Pluginloader and by plugin developers who don't need/want it.

I'll try to explain what I mean with an example based on a fictious plugin:

Code: Select all

<?php

$plugin_cf['fictious']['enable']="true";
$plugin_cf['fictious']['count']="123";
$plugin_cf['fictious']['title']="Fictious";
$plugin_cf['fictious']['message']="This is the fictious Fictious plugin.";
$plugin_cf['fictious']['password']="abcdefg";
$plugin_cf['fictious']['theme']="default";
$plugin_cf['fictious']['options']="small,simple,smart";

?>
And the following might be stored in the according metaconfig.php:

Code: Select all

<?php

$plugin_mcf['fictious']['enable']="bool";
$plugin_mcf['fictious']['count']="number";
$plugin_mcf['fictious']['title']="string";
$plugin_mcf['fictious']['message']="text";
$plugin_mcf['fictious']['password']="password";
$plugin_mcf['fictious']['theme']="select:default,red,green,blue";
$plugin_mcf['fictious']['options']="multi-select:small,simple,smart,standard-conforming,fast";

?>
This way the configuration handling in the back-end knows, with which input type the config option should be presented:
  • bool: a checkbox
  • number: an input type="text" (or for HTML5 an input type="number")
  • string: an input type="text"
  • text: a textarea
  • password: an input type="password"
  • select: a selectbox or radio buttons
  • multi-select: a selectbox or checkboxes
Please note that the "number" type is only to show that we might extend this for the new HTML5 input types (e.g. color, date, email etc.). The "select" and "multi-select" types might be configured in the CMS configuration to show selectboxes vs. radio buttons/checkboxes according to the users preferences.

Any comments, suggestions and improvements are welcome!

Christoph

PS: [1]
Christoph M. Becker – Plugins for CMSimple_XH

svasti
Posts: 1651
Joined: Wed Dec 17, 2008 5:08 pm

Re: XH 1.6: Different Kinds of Inputs for Config Forms

Post by svasti » Tue Oct 02, 2012 8:06 am

cmb wrote:easy to implement (for core and pluginloader), simple to use for plugin developers and that would work for older variants/versions of CMSimple and the pluginloader too.
+1
cmb wrote:The file is necessary only to build and save the configuration form, so it will not hurt general performance.
+1
cmb wrote:$plugin_cf['fictious']['enable']="true";
bool? Really?
I just tried:

Code: Select all

echo 'test';
$a = true;
$b = ($a == 'true')? 'works' : 'doesn\'t';
echo $b; 
Interesting, it works! I didn't expect that.

So I am looking forward to 1.6 :) :shock: :o

svasti

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: XH 1.6: Different Kinds of Inputs for Config Forms

Post by cmb » Tue Oct 02, 2012 9:52 am

svasti wrote:bool? Really?
The "bool" is meant only to signal that this option should be displayed as a checkbox, and when it's written back to the config file, what should be stored there: "true"/"" seems to be the most reasonable choice, as this will work with the two common variants how boolean config options are stored: "true"/"everything else" and "1"/"0". So plugins don't have to be modified as the following will still work:

Code: Select all

if ($plugin_cf['fictious']['enable']) {}
if ($plugin_cf['fictious']['enable']=='true') {}
if (preg_match('/true/i', $plugin_cf['fictious']['enable'])) {} 
A bit problematic might be "multi-select" as it's not clear, in which format the values should be stored (which delimiter?). Jerry's Newsrotator uses the comma, but other plugins/authors might have been using other delimiters.
Christoph M. Becker – Plugins for CMSimple_XH

simpleSolutions.dk
Posts: 155
Joined: Thu Oct 06, 2011 7:00 am

Re: XH 1.6: Different Kinds of Inputs for Config Forms

Post by simpleSolutions.dk » Thu Oct 04, 2012 10:12 pm

Hi Christoph

Newsrotator uses comma because the string is passed directly to jQuery cycles. Usually I use user defined delimiters.

Basicaly the configuration needs two types: single values and selection lists. So the simple solution could be to add optional select parameter {{{select:}}} to config.php instead of a new file with type definitions.
$plugin_cf['fictious']['theme']="green{{{select:default,red,green,blue}}}";
which will force cmsimple and pluginloader to show a dropdown with defined values and green as selected vaue.

The default could be {{{value:}}} which can be omitted for compatibilyt with earler version of CMSimple.
So the definition
$plugin_cf['fictious']['something']="something{{{value:something}}}";
is the same as
$plugin_cf['fictious']['something']="something";
And of course alternate types like bool can be defined if needed
$plugin_cf['fictious']['bool_selection']="true{{{bool:true,false}}}";
but it will be the same as
$plugin_cf['fictious']['bool_selection']="true{{select:true,false}}}";

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: XH 1.6: Different Kinds of Inputs for Config Forms

Post by cmb » Fri Oct 05, 2012 12:05 am

Hi Jerry,
simpleSolutions.dk wrote:Basicaly the configuration needs two types: single values and selection lists.
Indeed you're right! Particularly booleans can be seen as selection between true and false, and purely from a simple aesthetical view I'd rather prefer a selectbox with true/false over a checkbox in a simple auto generated form.

But the most important thing I had in mind was that plugins should work with the "new" and the "old" variant as well. Consider e.g. the "fictuous" plugin:

Code: Select all

$plugin_cf['fictious']['theme']="green{{{select:default,red,green,blue}}}"; 
With the current plugin loader this will be displayed as a textarea with the content: "green{{{select:default,red,green,blue}}}". That's not easily understandable by an end-user. Of course the web-designer could adjust this to "green", but after the update it has to be adjusted again to make use of the select box. And the plugin has to be adapted to cater for the new string format. Instead of simply writing e.g.:

Code: Select all

tag('link rel="stylesheet" href="' . $plugin_cf['fictious']['theme'] . '"') 
the plugin author first has to strip off the {{{select:...}}}, what's not hard to do, but would require a modification to the plugin.

Compare this to the alternative suggestion:

Code: Select all

$plugin_cf['fictuous']['theme']="green";
$plugin_tx['fictuous']['cf_theme']="Choose a theme: 'red', 'green' or 'blue'";
$plugin_mcf['fictuous']['theme']="select:red,green,blue"; 
In an old version of the pluginloader this will display a textarea with content "green" and the help message "Choose a theme: 'red', 'green' or 'blue'". And the plugin don't has to be changed:

Code: Select all

tag('link rel="stylesheet" href="' . $plugin_cf['fictious']['theme'] . '"') 
will work with the "old" and the "new" version of the pluginloader.

And if there would already be an additional file to specify the "type" of the option, it could be used to specify a more fine grained tuning of the display: a checkbox might be quite useful regarding internationalization, and already preparing for the new HTML5 input types might be a reasonable step into the future.

Christoph
Christoph M. Becker – Plugins for CMSimple_XH

simpleSolutions.dk
Posts: 155
Joined: Thu Oct 06, 2011 7:00 am

Re: XH 1.6: Different Kinds of Inputs for Config Forms

Post by simpleSolutions.dk » Fri Oct 05, 2012 2:40 pm

Hi Christoph

In my opinion two files are an overkill in relation to the future development of CMSimple. So I would prefer that we choose a solution which maybe is not completely compatible with earlier versions of CMSimple, but after all, is not destructive. It makes no sense to look back in order to maintain compatibility in this case.

CMSimple should exist for many years so we should not destroy the system architecture with to much regards for the past ;)

Holger
Site Admin
Posts: 3470
Joined: Mon May 19, 2008 7:10 pm
Location: Hessen, Germany

Re: XH 1.6: Different Kinds of Inputs for Config Forms

Post by Holger » Fri Oct 05, 2012 2:58 pm

simpleSolutions.dk wrote:In my opinion two files are an overkill in relation to the future development of CMSimple. So I would prefer that we choose a solution which maybe is not completely compatible with earlier versions of CMSimple
+1

KR
Holger

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: XH 1.6: Different Kinds of Inputs for Config Forms

Post by cmb » Sun Oct 07, 2012 10:00 pm

Hi Jerry, hi Holger,
simpleSolutions.dk wrote:So I would prefer that we choose a solution which maybe is not completely compatible with earlier versions of CMSimple
Well, I'm not sure that this is currently the best approach. Many users still have XH 1.4 and even older versions (consider the many CMSimple 3.x and even 2.x installations out there). And it's not clear, if CMSimpleSubsites will be compatible with any change regarding the configuration. I'm a bit afraid that many plugin developers won't actually switch to some format, that's incompatible with versions other than CMSimple_XH 1.6.

Requiring CMSimple_XH 1.6 for a plugin that makes use of the new config features would be much less a burden, if there would be some kind of semi-automatic update script. I'm working on that, but the biggest problem might be the plugins in general, and particularly old plugins, that can't be used with newer versions of CMSimple_XH. So settling on some conventions regarding a semi-automatic update for plugins might be helpful -- but that should be discussed in another thread.

However, for implementing the new features in CMSimple_XH the definite storage format is actually a secondary issue (that means it can finally be decided after implementing the solution), as it can and should be abstracted over anyway (both the suggested solutions are actually equivalent regarding the features). What's more important IMO is the actual set of "features", i.e. the available field types. Should we stick with the classic strings plus selection lists only, or should we extend this to a basically full-blown set of form field types (text-inputs, password fields, textareas, checkboxes and even the new HTML5 input-types)?

Christoph
Christoph M. Becker – Plugins for CMSimple_XH

svasti
Posts: 1651
Joined: Wed Dec 17, 2008 5:08 pm

Re: XH 1.6: Different Kinds of Inputs for Config Forms

Post by svasti » Tue Oct 09, 2012 9:21 pm

Hi all,

I would rather vote for a compatible solution.
So much less problems for automatic updating while there are old plugins.
cmb wrote:we extend this to a basically full-blown set of form field types (text-inputs, password fields, textareas, checkboxes and even the new HTML5 input-types)?
+1
yes, full blown set of possibilities, as you never know what you may need.
svasti

simpleSolutions.dk
Posts: 155
Joined: Thu Oct 06, 2011 7:00 am

Re: XH 1.6: Different Kinds of Inputs for Config Forms

Post by simpleSolutions.dk » Wed Oct 10, 2012 9:08 am

Sorry the long response time

My suggestion is actually fully compatible with the current configuration files. Most plugins use preg_match, stristr or eregi (I know it is deprecated) to get content of configurations strings and to avoid misspellings like an additinal space at the end of the string (cms.php is using equal sign but it is not the best solution and bedst of all, it can be changed). It means that any string content in config.php can be read and understood and even interprated. Let's look at an example
$plugin_cf['fictious']['theme']="green{{{select:default,red,green,blue}}}";
Using stristr or preg_mathc to request a value "green" will find the value in above string. It is may be not what a user expected but then a user will change the value in config.php to a value and a format compatible with his/hers CMSimple version.
yes, full blown set of possibilities, as you never know what you may need.
. Do we still talk about configuration? I do not hope that our mission is to make configuration unmanageable. Radio buttons and checkboxes does not any thing different then dropdowns, unless somebody needs multiple choice configuration :roll: : . Textareas?, a modern browser (expect IE) treats input fields as an expandable textarea, HTML5 input types configuration is not different from common input since HTML 2.0 (they are only specialized iinputfields).
To be honest we only need an dropdown selection, at least to begin with.

[EDIT]
May be we should start over and rewrite all configuration to XML

Post Reply