CMSIMPLE_ROOT can be wrong

A place to report and discuss bugs - please mention CMSimple-version, server, platform and browser version
Post Reply
cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

CMSIMPLE_ROOT can be wrong

Post by cmb » Fri Apr 11, 2014 3:42 pm

Hello Community,

inspired by a German support thread I had a closer look at the current definition of CMSIMPLE_ROOT (in cmsimple/cms.php):

Code: Select all

/**
 * The absolute path of the root folder.
 */
define(
    'CMSIMPLE_ROOT',
    str_replace('index.php', '', str_replace('/' . $sl . '/', "/", $sn))
); 
This can lead to false results, e.g. if an English CMSimple_XH installation is placed in a subfolder en/ of the webroot (or a subfolder thereof). In this case CMSIMPLE_ROOT == "/" instead of "/en/". Putting a CMSimple_XH installation in a path that contains a folder with two letters is traditionally not allowed, but this restriction was lifted with CMSimple_XH 1.5.7, so I regard the current behavior as a bug.

Furthermore there are some (rather theoretical) issues, because the current solution does not regard the position of the replacements (the search strings do not necessarily have to be at the end of $sn).

So, a solution would be to "shuffle" some of the definitions in cms.php and to use preg_replace() instead of str_replace():

Code: Select all

Index: cms.php
===================================================================
--- cms.php	(revision 3)
+++ cms.php	(working copy)
@@ -261,21 +261,52 @@
 }
 
 /**
+ * Whether the webserver is IIS.
+ *
+ * @global bool $iis
+ */
+$iis = strpos(sv('SERVER_SOFTWARE'), "IIS");
+
+/**
+ * Whether PHP is executed as (F)CGI.
+ *
+ * @global bool $cgi
+ */
+$cgi = (php_sapi_name() == 'cgi' || php_sapi_name() == 'cgi-fcgi');
+
+/**
+ * The relative path of the root folder, i.e. the script name.
+ *
+ * @global string $sn
+ */
+$sn = preg_replace(
+    '/([^\?]*)\?.*/', '$1',
+    sv(($iis ? 'SCRIPT_NAME' : 'REQUEST_URI'))
+);
+
+/**
  * The current language.
  *
  * @global string $sl
  */
-if (preg_match('/\/([A-z]{2})\/index.php$/', sv('SCRIPT_NAME'), $temp)
+if (preg_match('/\/([A-z]{2})\/index\.php$/', sv('SCRIPT_NAME'), $temp)
     && XH_isLanguageFolder($temp = strtolower($temp[1]))
 ) {
     $sl = $temp;
     $pth['folder']['content']
         = $pth['folder']['base'] . $cf['folders']['content'] . $sl . '/';
+    $temp = preg_replace('/[A-z]{2}\/(index\.php)?$/', '', $sn);
 } else {
     $sl = $cf['language']['default'];
     $pth['folder']['content'] = $pth['folder']['base'] . $cf['folders']['content'];
+    $temp = preg_replace('/index\.php$/', '', $sn);
 }
 
+/**
+ * The absolute path of the root folder.
+ */
+define('CMSIMPLE_ROOT', $temp);
+
 $pth['file']['content'] = $pth['folder']['content'] . 'content.htm';
 $pth['file']['pagedata'] = $pth['folder']['content'] . 'pagedata.php';
 $pth['file']['language'] = $pth['folder']['language'] . basename($sl) . '.php';
@@ -332,30 +363,6 @@
 );
 
 /**
- * Whether the webserver is IIS.
- *
- * @global bool $iis
- */
-$iis = strpos(sv('SERVER_SOFTWARE'), "IIS");
-
-/**
- * Whether PHP is executed as (F)CGI.
- *
- * @global bool $cgi
- */
-$cgi = (php_sapi_name() == 'cgi' || php_sapi_name() == 'cgi-fcgi');
-
-/**
- * The relative path of the root folder, i.e. the script name.
- *
- * @global string $sn
- */
-$sn = preg_replace(
-    '/([^\?]*)\?.*/', '$1',
-    sv(($iis ? 'SCRIPT_NAME' : 'REQUEST_URI'))
-);
-
-/**
  * The requested action.
  *
  * @global string $action
@@ -520,14 +527,6 @@
 }
 
 /**
- * The absolute path of the root folder.
- */
-define(
-    'CMSIMPLE_ROOT',
-    str_replace('index.php', '', str_replace('/' . $sl . '/', "/", $sn))
-);
-
-/**
  * The relative path of the root folder.
  */
 define('CMSIMPLE_BASE', $pth['folder']['base']);
I'm not sure whether to put that on the roadmap for XH 1.6.2 or XH 1.6.3, because 1.6.2 is frozen, and we have no clear rules regarding bugs--and this is a very minor bug.

Christoph
Christoph M. Becker – Plugins for CMSimple_XH

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

Re: CMSIMPLE_ROOT can be wrong

Post by svasti » Sat Apr 12, 2014 9:40 pm

cmb wrote:because 1.6.2 is frozen
why that? there was no agreement about that, there is simply no agreement yet.
Why should bug fixes, especially relatively easy ones, have the same deadline as fancy feature additions? Why not distinguish bug fixes, feature requests and combined bugfix/feature request in the roadmap? Simple bug fixes usually don't require much discussion, everybody usually wants them to be fixed.

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

Re: CMSIMPLE_ROOT can be wrong

Post by cmb » Sun Apr 13, 2014 5:47 pm

svasti wrote:there was no agreement about that, there is simply no agreement yet.
Indeed.
svasti wrote:Why should bug fixes, especially relatively easy ones, have the same deadline as fancy feature additions? Why not distinguish bug fixes, feature requests and combined bugfix/feature request in the roadmap? Simple bug fixes usually don't require much discussion, everybody usually wants them to be fixed.
I agree, but I don't know what the other team members think about it.
Christoph M. Becker – Plugins for CMSimple_XH

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

Re: CMSIMPLE_ROOT can be wrong

Post by Holger » Tue Apr 15, 2014 11:12 am

svasti wrote:Why should bug fixes, especially relatively easy ones, have the same deadline as fancy feature additions? Why not distinguish bug fixes, feature requests and combined bugfix/feature request in the roadmap? Simple bug fixes usually don't require much discussion, everybody usually wants them to be fixed.
+1

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

Re: CMSIMPLE_ROOT can be wrong

Post by cmb » Tue Apr 15, 2014 11:39 am

I've put it on the 1.6.2 roadmap.
Christoph M. Becker – Plugins for CMSimple_XH

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

Re: CMSIMPLE_ROOT can be wrong

Post by cmb » Mon May 12, 2014 11:18 am

After reconsideration I prefer another solution (r1281), because that is more localized and as such less error-prone.
Christoph M. Becker – Plugins for CMSimple_XH

Post Reply