Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

CSS relative path broken with some server DOCUMENT_ROOT settings #33

Closed
gs58muse opened this issue Apr 19, 2018 · 14 comments
Closed

CSS relative path broken with some server DOCUMENT_ROOT settings #33

gs58muse opened this issue Apr 19, 2018 · 14 comments
Assignees
Labels

Comments

@gs58muse
Copy link

Hello Nicolas

something is going wrong on my LIVE-SYSTEM with the "RELPATH" Var.
The "style.css" is not called.
The Problem is in the Var: "$_SERVER['DOCUMENT_ROOT']"

MY XAMPP TEST-SYSTEM:
P01C\PATH: C:\xampp_5.6.24\htdocs\test\plugins\p01-contact/
DOCUMENT_ROOT: C:/xampp_5.6.24/htdocs
RELPATH: \test\plugins\p01-contact/

MY LIVE SYSTEM: (Provider 1+1 or also Profihost)
Path: /homepages/0/d109796559/htdocs/test/plugins/p01-contact/
DOCUMENT_ROOT: /kunden/homepages/0/d109796559/htdocs
RELPATH: lugins/p01-contact/

The only Workaround for me to make it run:
define('P01C\RELPATH', dirname(substr(PAGEURL, strlen(SERVER)))."/plugins/p01-contact/");

Greetings
Gerhard

@nliautaud
Copy link
Owner

Hi,
Thanks for the report.

Indeed, it seems that your $_SERVER['DOCUMENT_ROOT'] server setting root is different than the __FILE__ output one, breaking the RELPATH stripping, which is used for the css path.

I can't use your workaround (it seems to me that substr(PAGEURL, strlen(SERVER)) is equivalent to PAGEURI) : I can't define the relative path from the direct parent of the uri, as the uri may have multiple levels, ex /mysite/foo/bar/, and I can't hardcode /plugins, as the script may be used as standalone or on several CMS with different files structures.

As an example, the script has to handle :

URL : domain.com/some/cms/foo/bar/contact-page
PATH : /user/0/123456/http/some/cms/plugins/p01-contact/
RELPATH : /some/cms/plugins/p01-contact/

I can't either compare the strings and look for similarities without risking
false positives.

Unfortunately the only way I know is to rely on DOCUMENT_ROOT 😕 .

@nliautaud nliautaud added the bug label Apr 19, 2018
@nliautaud nliautaud changed the title Problem with Var: RELPATH CSS relative path broken with some server DOCUMENT_ROOT settings Apr 19, 2018
@integratec
Copy link

integratec commented Aug 28, 2018

Hi,
same issue here (apache on debian, php 5.6). I solved ensuring a path separator exists when chaining SERVER and RELPATH constants.
In p01contact php starting at line 110:

       if (!$once) {
            $glue = '';
            if (RELPATH[0] != DIRECTORY_SEPARATOR) {
              $glue = '/';
            }
            $defaultStyle = '<link rel="stylesheet" href="' . SERVER . $glue . RELPATH . 'style.css"/>';
            $once = true;
        }

edit: changed to use DIRECTORY_SEPARATOR system constant in comparison insteaad of hardcoded slash.

@nliautaud
Copy link
Owner

Hi, thanks for the report.
Not sure if it's related or another issue.
Could you share your __FILE__, $_SERVER['DOCUMENT_ROOT'] and P01C\RELPATH values ?

@integratec
Copy link

Could you share your FILE, $_SERVER['DOCUMENT_ROOT'] and P01C\RELPATH values ?

__FILE__ : /var/www/plugins/p01-contact/src/P01contact.php
$_SERVER[DOCUMENT_ROOT] => /var/www/
[P01C\RELPATH] => plugins/p01-contact/

@nliautaud
Copy link
Owner

Thanks. The server is returning a valid document root, so it's a different cause.

Instead of a condition on newForm, I would normalize RELPATH to always start with a directory separator. Using '/' . ltrim(..., '/') on #L37 for example.

Would you make a Pull request ?

@integratec
Copy link

integratec commented Aug 30, 2018

Instead of a condition on newForm, I would normalize RELPATH to always start with a directory separator.

Sure it's better, I was thinking about but led it unthouched to avoid breaking something else because confused by the constant name. Now I checked actually it's not used elsewere.

Would you make a Pull request ?

Actually not, also because i'm working on my local svn repository so I need first forking your git repo.

@beejay41
Copy link

beejay41 commented Nov 19, 2018

and it can get worse!
My document root is a symlink to the physical files location, so that I can organise my projects. Which means the length of "document root" is significantly shorter than __DIR__.
For GS I've patched with:
define('P01C\RELPATH', '/'.str_replace(GSROOTPATH, '', PATH));
Not sure if that's a general solution for you. I probably shouldn't be using symlinks for document roots.

@nliautaud
Copy link
Owner

nliautaud commented Nov 19, 2018

@beejay41 indeed ! Could you test the PR #43 ? Tried a generalized way to get the root.

(@integratec @gs58muse too if possible)

@gs58muse
Copy link
Author

Hi,
testet #43
define('P01C\RELPATH', substr(PATH, strlen($_SERVER['DOCUMENT_ROOT'])));
also:
define('P01C\RELPATH', '/'.str_replace(GSROOTPATH, '', PATH));
dont work for me.
I have to to it the hard way:
define('P01C\RELPATH', substr($SITEURL, strlen(SERVER)). "plugins/p01-contact/");

@beejay41
Copy link

Yes, the "ROOT" solution works for me with my symlinks, and it avoids GS variable reliance.

Thanks,
Brian.

@nliautaud
Copy link
Owner

@gs58muse I didn't get if you tried the patch #43 SCRIPTNAME/SCRIPTPATH/ROOT solution (whitch doesn't rely on your DOCUMENT_ROOT setting) ? Could you give me the output of the constants in the debug report when using #43 ?

@nliautaud
Copy link
Owner

@beejay41 looks like a misunderstanding, I was asking gs58muse :) Thanks anyway, I deleted your reply as requested.

Repository owner deleted a comment from beejay41 Nov 22, 2018
@nliautaud nliautaud self-assigned this Nov 22, 2018
@gs58muse
Copy link
Author

gs58muse commented Nov 22, 2018 via email

@nliautaud
Copy link
Owner

Thanks everyone, will be shipped in the next release 👍

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants