XH 1.5.7: Detection of secondary Languages

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
cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

XH 1.5.7: Detection of secondary Languages

Post by cmb » Thu Feb 28, 2013 2:53 pm

Hello Community,

in the German section of this board Josef just reported a problem with a CMSimple installation in a subfolder of a folder with 2 letters, so I had a closer look what exactly happens. The problem is the detection of $sl in cmsimple/cms.php line 120f:

Code: Select all

if (preg_match('/\/[A-z]{2}\/[^\/]*/', sv('PHP_SELF')))
    $sl = strtolower(preg_replace('/.*\/([A-z]{2})\/[^\/]*/', '\1', sv('PHP_SELF'))); 
What this regex is supposed to do, is to check if the very folder containing index.php has two letters, so it will be treated as secondary language. But what it actually does is treating any folder with two letters in the path as secondary language as the regex is not anchored to the end of the string. The simple solution is to do so:

Code: Select all

if (preg_match('/\/[A-z]{2}\/[^\/]*$/', sv('PHP_SELF')))
    $sl = strtolower(preg_replace('/.*\/([A-z]{2})\/[^\/]*$/', '\1', sv('PHP_SELF'))); 
The duplicate regex might furthermore replaced with the following:

Code: Select all

if (preg_match('/\/([A-z]{2})\/[^\/]*$/', sv('PHP_SELF'), $temp))
    $sl = strtolower($temp[1]); 
And actually I don't see a reason to use PHP_SELF, as SCRIPT_NAME should do fine and would allow to keep the regex even more precise:

Code: Select all

if (preg_match('/\/([A-z]{2})\/index.php$/', sv('SCRIPT_NAME'), $temp)) {
    $sl = strtolower($temp[1]);
} 
(I consider the character class [A-z] as well as the strtolower() too fuzy, but we should keep it to not break existing sites, which might rely on this behavior.)

Please note, that it was already voted upon changing the detection of secondary languages to use a special file in the language folder (as it is handled by the subsite solution) for CMSimple_XH 1.6. IMO that is the best solution in the long run, but we should nonetheless fix the long standing restriction to have no 2-letter folders in the path (I consider it a minor bug, as it seems to be unintentional) for XH 1.5.7.

Christoph
Last edited by cmb on Tue Mar 19, 2013 11:14 pm, edited 1 time in total.
Reason: fixed typo
Christoph M. Becker – Plugins for CMSimple_XH

Post Reply