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!
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 » Wed Oct 10, 2012 10:45 am

Hi jerry,
simpleSolutions.dk wrote:My suggestion is actually fully compatible with the current configuration files.
simpleSolutions.dk wrote:Using stristr or preg_mathc to request a value "green" will find the value in above string.
That's not the complete truth. What about "lightgreen" and "darkgreen" as possible options?

But that's
simpleSolutions.dk wrote: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.
maybe the point we should think about as possible solution...

Holger

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 » Wed Oct 10, 2012 11:33 am

Hi,

I don't like the idea to introduce a new config-file to "configure the configuration", even if it seems to be the most "clean" and compatible solution.

So what about putting the definition of the config-fields to $plugin_tx[] like it's done with the tooltips?

Code: Select all

$plugin_cf['fictuous']['theme']="green";
$plugin_tx['fictuous']['cf_theme']="Choose a theme: 'red', 'green' or 'blue'";
$plugin_tx['fictuous']['mcf_theme']="select:red,green,blue"; 
   
That should be compatible in every case but has to be done in every language - which is bad style at all :? .

So I think using $plugin_cf is the best place to store the definitions:

Code: Select all

$plugin_cf['fictuous']['theme']="green";
$plugin_cf['fictuous']['cf_theme']="select:red,green,blue"; 
   
The cf_xxx shold not harm in older (core + PL) versions and older plugins, without cf_xxx entries, should be displayed in the configuration forms like today.
And, with this solution, updating an old plugin is just writing some definitions in config.php!

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 » Wed Oct 10, 2012 11:57 am

Hi Jerry, hi Holger,
simpleSolutions.dk wrote:My suggestion is actually fully compatible with the current configuration files
Actually it is! The only problem is, that a user having an "old" version of CMSimple(_XH) might be quite confused reading in the config form:

Code: Select all

       +------------------------------------------+
Theme: | green{{{select:default,red,green,blue}}} |
       +------------------------------------------+
Holger wrote:
simpleSolutions.dk wrote: Using stristr or preg_mathc to request a value "green" will find the value in above string.
That's not the complete truth. What about "lightgreen" and "darkgreen" as possible options?
And even worse: stristr($plugin_cf['fictous']['theme'], 'red') will return 'red'! A preg_match('/^red/i', $plugin_cf['fictuos']['theme']) will do the trick, but that means not only the configuration but also the plugin has to be (slightly) adpated. BTW: I consider the use of stristr() a bad practise for checking, if a string is contained in another. stripos() is much more effecient -- unfortunately it's available only since PHP 5, but a simple fallback can be easily written. If the substring contained non ASCII characters a UTF-8 aware variant would be necessary anyway.
simpleSolutions.dk wrote: I do not hope that our mission is to make configuration unmanageable.
Unmanagable for whom?
  • it shouldn't be too hard to implement the configuration management for the core
  • the plugin author could simply ignore the "types" he doesn't consider useful
  • the end-user might prefer a checkbox over a selectbox; if options will be presented as a group of radiobuttons or a selectbox should be configurable, so the user is able to choose, what he prefers; the new HTML5 input types are currently at most partially supported on the most common browsers, but that's quite likely going to change in the future.
simpleSolutions.dk wrote:Textareas?, a modern browser (expect IE) treats input fields as an expandable textarea
I'm not aware of any such browser. Perhaps you mean textareas with rows=1? Indeed these textareas are quite versatile, but they have the disadvantage that pressing return inserts a line break, instead of submitting the form, what a user expects for input fields (see http://cmsimpleforum.com/viewtopic.php?f=16&t=3991).
Holger wrote:So what about putting the definition of the config-fields to $plugin_tx[] like it's done with the tooltips?
...
So I think using $plugin_cf is the best place to store the definitions:
I've thought about this too. But than we might use a second file as well, as this is actually more efficient, as it doesn't have to be read most of the time (never in the front-end, and only if a config form is called or saved).
simpleSolutions.dk wrote:May be we should start over and rewrite all configuration to XML
IMHO XML might have it's use, but it's a poor choice for data storage. Consider:
unknown wrote:"XML combines the efficiency of text files with the readability of binary files"
(more critique of XML can be found on http://harmful.cat-v.org/software/xml/ and http://c2.com/cgi/wiki?XmlSucks).

And to process XML with PHP 4 one has to use the xml extension. As it's a SAX parser it's good for processing large XML documents, but it's rather inconvenient to handle.

But anyway, changing the config format to something incompatible should better wait for CMSimple_XH 2.

Christoph
Christoph M. Becker – Plugins for CMSimple_XH

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 » Wed Oct 10, 2012 1:04 pm

Hmm,
cmb wrote:But anyway, changing the config format to something incompatible should better wait for CMSimple_XH 2.
at a long run the best choice might braking with compatibility of $plugin_cf[] one day (2.0? - we're talking about this version since years ;-) ).
I agree that that's nothing to discuss this time.
But IMO even with 2.0 it might not be necessary to break, if we find a good solution right now...
cmb wrote:I've thought about this too. But than we might use a second file as well, as this is actually more efficient, as it doesn't have to be read most of the time (never in the front-end, and only if a config form is called or saved).
I don't want to start a discussion about how much more efficient a second file is, because you're right: it is of course more efficient. And, of course, it's flexible and compatible.

The only thing is: I just don't like the second file. But, if others agree, it's fine with me too and I hope that this feature comes soon...

Holger

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 » Wed Oct 10, 2012 1:20 pm

have put in on the roadmap for 1.6

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 » Wed Oct 10, 2012 2:34 pm

svasti wrote:have put in on the roadmap for 1.6
I did already put it there directly after opening the thread -- now we have DC ;)
Holger wrote:I don't want to start a discussion about how much more efficient a second file is, because you're right: it is of course more efficient. And, of course, it's flexible and compatible.

The only thing is: I just don't like the second file. But, if others agree, it's fine with me too and I hope that this feature comes soon...
Basically that's no problem too. Conceptionally it doesn't matter where the "meta" information is stored. One can have two files:

Code: Select all

// config.php
$plugin_cf['fictuous']['theme']="green";

// metaconfig.php
$plugin_mcf['fictuous']['theme']="select:default,red,green,blue"; 
or one combined file:

Code: Select all

// config.php
$plugin_cf['fictuous']['theme']="green";
$plugin_mcf['fictuous']['theme']="select:default,red,green,blue"; 
The plugin author could decide this as he likes (the processing code in the core would have been slightly extended: if (isset($plugin_mcf) && !file_exists('metaconfig.php') {// store $plugin_mcf in config.php}); and even the end-user could change this. The only drawback of putting the meta info in config.php is, that it is deleted after saving from an old version.

But we might as well decide to have only one file, and even only one variable.

Christoph
Christoph M. Becker – Plugins for CMSimple_XH

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

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

Post by Tata » Wed Oct 10, 2012 4:42 pm

I personally would prefere separated file for storin meta data. I see the advantage in eventuall re-building/upgrading a website. The config may change whatever reason. But for me it would be necessary to copy only the matadata.php, instead of copy/pasting line from old config to the new one. Anyway, it happens very seldom, so the check wicih way is used - and the consequentialy storing into the config or metadata files is also comfortable.
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.

Gert
Posts: 3078
Joined: Fri May 30, 2008 4:53 pm
Location: Berlin
Contact:

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

Post by Gert » Sat Oct 13, 2012 4:17 pm

Tata wrote:I personally would prefere separated file for storin meta data.
Me to, but please optional, plugins should also work without the separate file, as now,

Gert
Gert Ebersbach | CMSimple | Templates - Plugins - Services

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

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

Post by Tata » Mon Oct 15, 2012 9:28 pm

Gert wrote:... but please optional...
This would be very nice flexibility and it also would fit both to beginners and advanced end users. If this would not make a problem to write codes this way, it would be a big step forward.
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: 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 Nov 18, 2012 9:01 pm

Hello Community,

nearly 5 weeks have past and this topic is still not decided upon. So I've implemented a minimal solution for demonstration purposes. This is meant as patch for the development snapshot (just copy the content of the ZIP file in your CMSimple_XH root folder). The following field types are available: string (text input), text (textarea), bool (checkbox), enum (selectbox). For now it does only work for the plugin configuration. A metaconfig file for pagemanager is already included. You can add metaconfig files for other plugins yourself, if you like to see how that looks and what's currently possible.

The necessary changes to FileEdit.php were rather minimal:

Code: Select all

Index: FileEdit.php
===================================================================
--- FileEdit.php    (revision 375)
+++ FileEdit.php    (working copy)
@@ -164,10 +164,6 @@
     {
         $iname = XH_FORM_NAMESPACE . $cat . '_' . $name;
         switch ($opt['type']) {
-        case 'string':
-            return tag('input type="text" name="' . $iname . '" value="'
-                       . htmlspecialchars($opt['val'], ENT_QUOTES, 'UTF-8')
-                       . '" class="cmsimplecore_settings"');
         case 'password':
             return tag('input type="text" name="' . $iname . '" value="'
                        . htmlspecialchars($opt['val'], ENT_QUOTES, 'UTF-8')
@@ -195,6 +191,10 @@
             }
             $o .= '</select>';
             return $o;
+        default:
+            return tag('input type="text" name="' . $iname . '" value="'
+                       . htmlspecialchars($opt['val'], ENT_QUOTES, 'UTF-8')
+                       . '" class="cmsimplecore_settings"');
         }
     }
     
@@ -238,7 +238,11 @@
         foreach ($this->cfg as $cat => $opts) {
             foreach ($opts as $name => $opt) {
         $iname = XH_FORM_NAMESPACE . $cat . '_' . $name;
-        $val = stsl($_POST[$iname]);
+        if ($opt['type'] == 'bool') {
+            $val = isset($_POST[$iname]) ? 'true' : '';
+        } else {
+            $val = stsl($_POST[$iname]);
+        }
         if ($opt['type'] == 'password'
             && $_POST[$iname] != $_POST[$iname . '_OLD'])
         {
@@ -436,6 +440,11 @@
         global $pth, $plugin, $plugin_cf, $plugin_tx;
         
     parent::XH_PluginArrayFileEdit();
+    $fn = $pth['folder']['plugins'] . $plugin . '/config/metaconfig.php';
+    if (is_readable($fn)) {
+        include $fn;
+    }
+    $mcf = isset($plugin_mcf[$plugin]) ? $plugin_mcf[$plugin] : array();
     $this->filename = $pth['file']['plugin_config'];
     $this->params = array('admin' => 'plugin_config',
                   'action' => 'plugin_save');
@@ -444,7 +453,14 @@
         $this->cfg = array();
         foreach ($plugin_cf[$plugin] as $key => $val) {
             list($cat, $name) = $this->splitKey($key);
-            $co = array('val' => $val, 'type' => 'string');
+        $type = isset($mcf[$key]) ? $mcf[$key] : 'string';
+        if (strpos($type, 'enum:') === 0) {
+        $vals = explode(',', substr($type, strlen('enum:')));
+        $type = 'enum';
+        } else {
+        $vals = null;
+        }
+            $co = array('val' => $val, 'type' => $type,  'vals' => $vals);
             if (isset($plugin_tx[$plugin]["cf_$key"])) {
                 $co['hint'] = $plugin_tx[$plugin]["cf_$key"];
             } 
and it should be easy to add further field types.

As already written it's possible to store the meta information in other ways; this was only the most simple (as it has not to be stored back) and the most compatible way for existing plugins.

Christoph
Christoph M. Becker – Plugins for CMSimple_XH

Post Reply