how to create one config by template with v1.7
how to create one config by template with v1.7
Hi all,
I had created a plugin that apparently did not interest anyone.
But it seems that a few rare users remain interested by Glossaire_XH
Could I ask a question to the developers of version 1.7 of CMSimple_XH ?
Could you tell me how to properly use config.php of my plugin to allow one configuration by template.
Before version 1.7 (1.6.x):
$plugin_cf was an array variable.
The config.php file of my plugin contained the values corresponding to the default configuration.
I gave the user the possibility to save a configuration for each template used.
A configuration file dedicated to this template was then created (there was potentially one for each template).
Then, for a template used, if the dedicated configuration file existed, I realized an include and thus updated the $config_cf variables.
Since version 1.7:
$plugin_cf has become an object.
I can not do what I did before.
Question:
You who created this object $plugin_cf,
how can a plugin use it to allow configuration by template.
It is necessary that when a template is used -and that the configuration has already been created for this template-, its dedicated configuration can be loaded as I did before with an include.
Currently, I can not update the variables anymore. Whatever I do, these remain as they are in config.php.
Even if an include of a different configuration is loaded, it does not change these variables.
I hope I have been clear enough. I speak only a little English and I have no notion of German.
Thanks for reading me,
hoping to get an answer and that I can understand it,
best regards,
Ludovic
[Glossaire_XH]
I had created a plugin that apparently did not interest anyone.
But it seems that a few rare users remain interested by Glossaire_XH
Could I ask a question to the developers of version 1.7 of CMSimple_XH ?
Could you tell me how to properly use config.php of my plugin to allow one configuration by template.
Before version 1.7 (1.6.x):
$plugin_cf was an array variable.
The config.php file of my plugin contained the values corresponding to the default configuration.
I gave the user the possibility to save a configuration for each template used.
A configuration file dedicated to this template was then created (there was potentially one for each template).
Then, for a template used, if the dedicated configuration file existed, I realized an include and thus updated the $config_cf variables.
Since version 1.7:
$plugin_cf has become an object.
I can not do what I did before.
Question:
You who created this object $plugin_cf,
how can a plugin use it to allow configuration by template.
It is necessary that when a template is used -and that the configuration has already been created for this template-, its dedicated configuration can be loaded as I did before with an include.
Currently, I can not update the variables anymore. Whatever I do, these remain as they are in config.php.
Even if an include of a different configuration is loaded, it does not change these variables.
I hope I have been clear enough. I speak only a little English and I have no notion of German.
Thanks for reading me,
hoping to get an answer and that I can understand it,
best regards,
Ludovic
[Glossaire_XH]
Re: how to create one config by template with v1.7
Maybe this scenario can work:
1. let the plugin reading what is the actual template
2. let the plugin create new copy of glossaire/config/config.php config for the active template renamed to e.g.: config_<active_template_name>.php
3. let the glossaire/index.php to test the active template and load the respective config_<active_template_name>.php
1. let the plugin reading what is the actual template
2. let the plugin create new copy of glossaire/config/config.php config for the active template renamed to e.g.: config_<active_template_name>.php
3. let the glossaire/index.php to test the active template and load the respective config_<active_template_name>.php
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.
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.
Re: how to create one config by template with v1.7
that's exactly what I did.
But it's always the configuration from config.php that takes precedence.
I have already done the following test:
In index.php, test the variables from $plugin_cf just after loading the configuration for the template used.
Well, these variables still retain the values from config.php.
Apparently, it is not expected that the object $plugin_cf allows the existence of several possible configurations.
Unless there is a trick to "force" the refresh of $plugin_cf values ...
But I do not know object-oriented programming ...
Thank you for your answer.
But it's always the configuration from config.php that takes precedence.
I have already done the following test:
In index.php, test the variables from $plugin_cf just after loading the configuration for the template used.
Well, these variables still retain the values from config.php.
Apparently, it is not expected that the object $plugin_cf allows the existence of several possible configurations.
Unless there is a trick to "force" the refresh of $plugin_cf values ...
But I do not know object-oriented programming ...
Thank you for your answer.
Re: how to create one config by template with v1.7
Hi Ludovic,
JFTR: $plugin_cf is treated as read-only since XH 1.6 if I'm right.
Anyway, here's my workaround to load additional settings based on config.php :
1st step:
create a copy of your plugins configuration array at the very beginning of your index.php
From now use only the copy of the array in your code.
2nd step:
create a little function to handle a copy of config.php in the template folder and to load a changed configuration.
We'll replace the original $plugin_cf... with our copy and include the array at the end.
(Just a draft, untested, only to show the idea behind):
Now always call readConfig() instead of include config.php.
JFTR: $plugin_cf is treated as read-only since XH 1.6 if I'm right.
Anyway, here's my workaround to load additional settings based on config.php :
1st step:
create a copy of your plugins configuration array at the very beginning of your index.php
Code: Select all
$pcf = $plugin_cf['glossaire'];
2nd step:
create a little function to handle a copy of config.php in the template folder and to load a changed configuration.
We'll replace the original $plugin_cf... with our copy and include the array at the end.
(Just a draft, untested, only to show the idea behind):
Code: Select all
function readConfig() {
global $pth;
$config = $pth['folder']['template'] . 'config.php';
if (file_exists($config) {
$t = file_get_contents($config);
if (strpos('$plugin_cf['glossaire']', $t)) {
str_replace('$plugin_cf['glossaire']', '$pcf', $t);
file_put_contents($config, $t);
}
include $config;
}
}
Re: how to create one config by template with v1.7
Hi Holger,
and thank you very much for that detailed answer.
I am going to try it as soon as possible
and thank you very much for that detailed answer.
I am going to try it as soon as possible
Re: how to create one config by template with v1.7
First, let me quickly explain why this has changed. The main reason was to avoid loading configuration files which are not required for the request (see viewtopic.php?f=29&t=12012#p59038). More of a side effect, but still a Good Thing in my opinon, has been to abstract over the concrete format of the configuration files.
After this code has been executed, $glossaire_config has the same content as $plugin_cf['glossaire']. The main benefit of using XH_includeVar() is that you don't have to assume a particular config file format.
A slight variation of Holger's suggestion:
Code: Select all
<?php
function glossaire_readConfig() {
global $pth;
$config = $pth['folder']['template'] . 'config.php';
if (file_exists($config)) {
return XH_includeVar($config, 'plugin_cf')['glossaire'];
}
}
$glossaire_config = glossaire_readConfig();
Christoph M. Becker – Plugins for CMSimple_XH
Re: how to create one config by template with v1.7
thanks cmb, it works perfectly. Indeed, it's very simple.
I did not have to modify much and I should be able to offer a compatible version with CMSimple_XH 1.7 shortly.
(It remain a little problem with newsboxes...)
thanks again holger and cmb.
I did not have to modify much and I should be able to offer a compatible version with CMSimple_XH 1.7 shortly.
(It remain a little problem with newsboxes...)
thanks again holger and cmb.
Re: how to create one config by template with v1.7
New Glossaire_XH version 2.0 is now available and compatible with CMSimple_XH V1.7.x
https://www.f5swn.fr/en/?Plugins/Glossaire
As it seems that a few rare users appreciate it, it is back
https://www.f5swn.fr/en/?Plugins/Glossaire
As it seems that a few rare users appreciate it, it is back