Reliable setting of $s

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: 12931
Joined: Tue Jun 21, 2011 11:04 am
Location: Mü-Sa, RLP, DE
Contact:

Reliable setting of $s

Post by cmb » Fri Sep 28, 2012 7:04 pm

Hello Community,

I've just had a problem with $s regarding the start page of the CMSimple installation, if this is called without the page name, e.g. http://www.example.com/. In this case $s == -1 while the plugins are loaded, and will be set only after this step in adm.php. IMO that's too late. Any plugin should have access to a reliable $s even in the loading stage (i.e. in the global scope of index.php and admin.php).

A simple workaround that shouldn't interfere with existing plugins, addons or customizations would be to treat an emtpy query string as calling the start page, if $selected is not set. That would require only some additional lines in rfc(), but it won't handle all cases.

A clean solution is probably not possible without causing many existing plugins and perhaps some websites to break. But IMO it's necessary in the long run to fix this issue.

One solution might be, to declare the first query parameter as name of the page, that should be called (as it's now). If the first parameter is empty, then the start page is meant (i.e. $s == 0). But this would require to treat special calls (e.g. sitemap, images, xhpages and the plugins) as "implicit" pages, so no page with the same name (case sensitive) may exist on the same site. Some examples of the resulting URLs (please note the "?" vs. "?&"):
http://www.example.com/
http://www.example.com/?sitemap
http://www.example.com/?&print
http://www.example.com/?downloads
http://www.example.com/?&download=file.pdf
http://www.example.com/?&logout
http://www.example.com/?pagemanager&adm ... lugin_text

Any comments, ideas, suggestions and questions are welcome.

Christoph
Last edited by cmb on Sun Dec 02, 2012 11:46 am, edited 1 time in total.
Reason: fixed typo
Christoph M. Becker –Plugins for CMSimple_XH

svasti
Posts: 1649
Joined: Wed Dec 17, 2008 5:08 pm
Location: Bielefeld, Germany
Contact:

Re: Reliable setting of $s

Post by svasti » Sat Sep 29, 2012 8:50 am

cmb wrote:I've just had a problem with $s regarding the start page of the CMSimple installation, if this is called without the page name, e.g. http://www.example.com/. In this case $s == -1
Really? Please go to CMSimple-xh.com -- there is a small change -- and, do you see the flags for other languages?

The text before the flgs used to be "select other languages". I changed it to: "Links to CMSimple_XH sites in other languages:". It shows only when $s==0.
Seems to work.

svasti

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

Re: Reliable setting of $s

Post by cmb » Sat Sep 29, 2012 10:09 am

svasti wrote:Really?
Not quite, but the following is correct:
cmb wrote:I've just had a problem with $s regarding the start page of the CMSimple installation, if this is called without the page name, e.g. http://www.example.com/. In this case $s == -1 while the plugins are loaded
The important point: $s == -1 during loading of the plugins. It's fixed afterwards, so it's fine to rely on a correctly set $s in the template. But it doesn't work for plugins and in userfuncs.php. Proof: add the following userfuncs.php:

Code: Select all

<?php

var_dump($s); 
svasti wrote:I changed it to: "Links to CMSimple_XH sites in other languages:". It shows only when $s==0.
That's probably a good idea as the flags on every single page are misleading (cf. http://cmsimpleforum.com/viewtopic.php? ... 282#p30282).
Christoph M. Becker –Plugins for CMSimple_XH

svasti
Posts: 1649
Joined: Wed Dec 17, 2008 5:08 pm
Location: Bielefeld, Germany
Contact:

Re: Reliable setting of $s

Post by svasti » Sat Sep 29, 2012 10:43 am

cmb wrote:$s == -1 during loading of the plugins
:shock: var_dump confirms it :o

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

Re: Reliable setting of $s

Post by cmb » Sat Sep 29, 2012 11:08 am

svasti wrote: :shock: var_dump confirms it :o
And it's not only a theoretical problem. The Templateswitch_XH has the same problem (see http://cmsimpleforum.com/viewtopic.php? ... 38&p=29468, which contains some additional explanation what's happening in adm.php to fix $s). Yesterday I had the problem with the cart preview of the Wellrad shop (doesn't show up, when the domain is called directly). And basically the problem exists for every plugin, that (temporarily) alters the content of the current page ($c[$s]) or the output ($o) directly when the plugin is loaded.

It's hard to fix this in the plugin reliably (checking for an empty query string doesn't cater for all possibilities). The only way for plugins to circumvent potential problems is to avoid such automatic content manipulation, and require the user to manually put in a call from the content or template to a plugin function. But this isn't the most convenient solution for users, and it isn't an option in some cases (e.g. Templateswitch would require the user to modify all the templates).
Christoph M. Becker –Plugins for CMSimple_XH

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

Re: Reliable setting of $s

Post by Gert » Sat Sep 29, 2012 5:46 pm

cmb wrote:And it's not only a theoretical problem. The Templateswitch_XH has the same problem
TemplateSwitch_XH works fine, even if the blank domain is called:

http://www.ge-webdesign.de/plugindemo/

Gert
Gert Ebersbach | CMSimple | Templates - Plugins - Services

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

Re: Reliable setting of $s

Post by cmb » Sat Sep 29, 2012 5:59 pm

Hi Gert,

just set show_always_selectbox=='true', activate the mailform and send a mail. Below the information that the mail was successfully sent, you'll see the content of the start page.

Christoph
Christoph M. Becker –Plugins for CMSimple_XH

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

Re: Reliable setting of $s

Post by Gert » Sat Sep 29, 2012 6:21 pm

cmb wrote:Below the information that the mail was successfully sent, you'll see the content of the start page.
I have activated the mailform now: http://www.ge-webdesign.de/plugindemo/

Please test it (send me a mail),

Gert

PS: TemplateSwitch_XH 2.1 is available since 2012-08-10
Gert Ebersbach | CMSimple | Templates - Plugins - Services

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

Re: Reliable setting of $s

Post by cmb » Sun Sep 30, 2012 12:07 pm

Hi Gert,

I've just tested it, and it works fine with the new version (2.1) :) But IMO a workaround in any plugin isn't the best solution. One one hand it's more than hard to fix all cases (e.g. a plugin on the start page that has some kind of "pagination"); on the other that might cause all kinds of interference between plugins.

For example: I've installed CMSimpleRealblog 2.1, and put the WebLog page as first page. Then I've installed Templateswitch_XH 2.1. When I call the start page without any parameter, everything is fine. But when I click on "read more", the article isn't shown. It works fine, though, if I call ?WebLog in the first place.

So I still suggest that we find some solution to set $s correctly before the plugins are loaded.

Additionally I found another minor issue: on http://www.ge-webdesign.de/plugindemo/?_Registrieren the template selectbox is displayed below the registration form. I assume it would be the other way round, when the plugins were loaded in reverse order.

Christoph
Christoph M. Becker –Plugins for CMSimple_XH

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

Re: Reliable setting of $s

Post by cmb » Sun Dec 30, 2012 1:11 pm

AISB it's probably not possible to set $s reliably without breaking existing plugins. So I suggest for XH 1.6 we settle on a convention, how the URLs should be constructed, so that it would be possible to reliably set $s before the plugins are loaded, but don't actually change the handling as it's now. In a later version we can then change the detection of the currently selected page. This would give plugin authors hopefully sufficient time to adapt their plugins.

For this convention, we have to consider POST requests too, which might use $selected. And we might think about simplifying/unifying different ways to trigger some special behavior: $su, $selected, $function, $action.
Christoph M. Becker –Plugins for CMSimple_XH

Post Reply