nliautaud / p01contact

Create contact forms by writing simple tags. Also a plugin for GetSimple and Pico CMS.
MIT License
16 stars 15 forks source link

CSS relative path broken with some server DOCUMENT_ROOT settings #33

Closed gs58muse closed 5 years ago

gs58muse commented 6 years ago

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 commented 6 years ago

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 😕 .

integratec commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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

(@integratec @gs58muse too if possible)

gs58muse commented 5 years ago

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 commented 5 years ago

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

Thanks, Brian.

nliautaud commented 5 years ago

@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 commented 5 years ago

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

gs58muse commented 5 years ago

Hi Nicolas,

Great - it works for me.

The form will be displayed correctly

The RELPATH is OK (the form will call the stylesheet correctly)

Thanks

@gs58muse https://github.com/gs58muse

From: Nicolas Liautaud [mailto:notifications@github.com] Sent: Wednesday, November 21, 2018 5:53 PM To: nliautaud/p01contact p01contact@noreply.github.com Cc: gs58muse gsms50@t-online.de; Mention mention@noreply.github.com Subject: Re: [nliautaud/p01contact] CSS relative path broken with some server DOCUMENT_ROOT settings (#33)

@gs58muse https://github.com/gs58muse I didn't get if you tried the patch #43 https://github.com/nliautaud/p01contact/pull/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 https://github.com/nliautaud/p01contact/pull/43 ?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/nliautaud/p01contact/issues/33#issuecomment-440736645 , or mute the thread https://github.com/notifications/unsubscribe-auth/Aj_oDBpA74vVYl9ODkpKqUvhQKmQBr8zks5uxYUCgaJpZM4TbbYx . https://github.com/notifications/beacon/Aj_oDIuCpAGOjo7bGHgFzBnQpj6P_8-Bks5uxYUCgaJpZM4TbbYx.gif

Health :

PHP version : 7.1.24 PHP mbstring (UTF-8) : OK

Constants :

Array ( [P01C\VERSION] => 1.1.4 [P01C\SERVERNAME] => seipel.de [P01C\SERVERPORT] => 80 [P01C\SCRIPTNAME] => /gsdev/index.php [P01C\SCRIPTPATH] => /homepages/0/d109796559/htdocs/gsdev/index.php [P01C\HTTPS] => [P01C\PORT] => [P01C\PROTOCOL] => http [P01C\SERVER] => http://seipel.de [P01C\PAGEURI] => /gsdev/index.php?id=kontakt [P01C\PAGEURL] => http://seipel.de/gsdev/index.php?id=kontakt [P01C\PATH] => /homepages/0/d109796559/htdocs/gsdev/plugins/p01-contact/ [P01C\ROOT] => /homepages/0/d109796559/htdocs [P01C\RELPATH] => /gsdev/plugins/p01-contact/ [P01C\LANGSPATH] => /homepages/0/d109796559/htdocs/gsdev/plugins/p01-contact/lang/ [P01C\TPLPATH] => /homepages/0/d109796559/htdocs/gsdev/plugins/p01-contact/src/templates/ [P01C\CONFIGPATH] => /homepages/0/d109796559/htdocs/gsdev/plugins/p01-contact/config.json [P01C\LOGPATH] => /homepages/0/d109796559/htdocs/gsdev/plugins/p01-contact/log.json [P01C\REPOURL] => https://github.com/nliautaud/p01contact [P01C\WIKIURL] => https://github.com/nliautaud/p01contact/wiki [P01C\ISSUESURL] => https://github.com/nliautaud/p01contact/issues [P01C\APILATEST] => https://api.github.com/repos/nliautaud/p01contact/releases/latest )

nliautaud commented 5 years ago

Thanks everyone, will be shipped in the next release 👍