scripting
-
- Posts: 28
- Joined: Sat Jul 07, 2012 6:16 pm
- Location: Budapest, Hungary
scripting
Hello everybody,
first of all, Happy New Year to all cmsimple fans!
Sometimes in content.htm file I need to use geturl function which is working fine with absolut url path, but not with relative ones.
- geturl('http://www.mydomain.com/folder1/page.php?&print') -- OK
- geturl('../folder1/page.php?&print') -- ng (not good) - give an empty page.
Can someone please help to make the geturl function also working with relative paths too?
Thank you in advance,
Alex
first of all, Happy New Year to all cmsimple fans!
Sometimes in content.htm file I need to use geturl function which is working fine with absolut url path, but not with relative ones.
- geturl('http://www.mydomain.com/folder1/page.php?&print') -- OK
- geturl('../folder1/page.php?&print') -- ng (not good) - give an empty page.
Can someone please help to make the geturl function also working with relative paths too?
Thank you in advance,
Alex
Re: scripting
Indeed, geturl() is designed to work with fully qualified absolute URLs only.stargazer96 wrote:Sometimes in content.htm file I need to use geturl function which is working fine with absolut url path, but not with relative ones.
You may try the following untested code (based on CMSimple 3.4 and CMSimple_XH's definition of CMSIMPLE_URL):stargazer96 wrote:Can someone please help to make the geturl function also working with relative paths too?
Code: Select all
function geturl($u) {
global $sn;
$u = 'http'
. (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 's' : '')
. '://' . $_SERVER['HTTP_HOST'] . $sn . $u;
$t = '';
if ($fh = @fopen(preg_replace("/\&/is", "&", $u), "r")) {
while (!feof($fh))$t .= fread($fh, 1024);
fclose($fh);
return preg_replace("/.*<body[^>]*>(.*)<\/body>.*/is", "\\1", $t);
}
}
Christoph M. Becker – Plugins for CMSimple_XH
-
- Posts: 28
- Joined: Sat Jul 07, 2012 6:16 pm
- Location: Budapest, Hungary
Re: scripting
Thank you very much for the answer, Christoph and Happy New Year for you!
It woks, but unfortunatelly work only if pages are in the root (and not in subfolders), but the main problem is that takes a while -a looooong time period- to load (and dispay) the page.
Maybe because I am using clear urls (with "_" uri seperator , and without the "?"), or have nothing to do with this aspect ?
Alex
It woks, but unfortunatelly work only if pages are in the root (and not in subfolders), but the main problem is that takes a while -a looooong time period- to load (and dispay) the page.
Maybe because I am using clear urls (with "_" uri seperator , and without the "?"), or have nothing to do with this aspect ?
Alex
-
- Posts: 28
- Joined: Sat Jul 07, 2012 6:16 pm
- Location: Budapest, Hungary
Re: scripting
or -just a though-, would it be also possible to use an other function, maybe 'file_get_contents'?
Re: scripting
Happy new year to you, too!
to
I suggest you compare the loading time with the alternative approach of including the page in an IFrame, for instance:
Anyway, you may try GXGetUrl.
It might be useful to remove the $sn variable. Change:stargazer96 wrote:It woks, but unfortunatelly work only if pages are in the root (and not in subfolders), […]
Code: Select all
$u = 'http'
. (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 's' : '')
. '://' . $_SERVER['HTTP_HOST'] . $sn . $u;
Code: Select all
$u = 'http'
. (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 's' : '')
. '://' . $_SERVER['HTTP_HOST'] . $u;
Some delay is to be expected. geturl() requests a document via HTTP(s) (what may take quite a while), and blocks further script execution while fetching the response.stargazer96 wrote:[…] but the main problem is that takes a while -a looooong time period- to load (and dispay) the page.
I suggest you compare the loading time with the alternative approach of including the page in an IFrame, for instance:
Code: Select all
<iframe src="../folder1/page.php?&print"></iframe>
file_get_contents() may be (slightly) faster than the fopen() used by geturl(), but you'd still need to remove everything outside of the <body> element (a preg_match() might be faster as the current preg_replace()).stargazer96 wrote:or -just a though-, would it be also possible to use an other function, maybe 'file_get_contents'?
Anyway, you may try GXGetUrl.
Christoph M. Becker – Plugins for CMSimple_XH
-
- Posts: 28
- Joined: Sat Jul 07, 2012 6:16 pm
- Location: Budapest, Hungary
Re: scripting
in this case (with removed $sn) gave -after half-, or one minute waiting- a "504 Gateway Time-out".
I will try also GXGetUrl, thank you, I already download it.
I will try also GXGetUrl, thank you, I already download it.
-
- Posts: 28
- Joined: Sat Jul 07, 2012 6:16 pm
- Location: Budapest, Hungary
Re: scripting
Thank you very much Christoph, seems that your solution is started to working well.
I will test it again also tomorrow and will reply soon.
Thanks a lot for your valuable help!
Alex
I will test it again also tomorrow and will reply soon.
Thanks a lot for your valuable help!
Alex
-
- Posts: 28
- Joined: Sat Jul 07, 2012 6:16 pm
- Location: Budapest, Hungary
Re: scripting
With slight / small modifications it start working.
THANK YOU very much for the help !
THANK YOU very much for the help !