You need to log in before you can comment on or make changes to this bug.
Using CVS version, legend template cannot be found with relative paths or http: paths.
I did some (lol, quite a lot) digging and it seems this issue is common...in fact paul mentioned a fix in the code to a user: http://lists.maptools.org/pipermail/chameleon/2004-January/000369.html As Paul suggested, in legendtemplate.widget.php I changed lines 95 to 99 to: if (strcmp(substr($this->mszTemplate, 0, 1), "/") != 0 && strcmp(substr($this->mszTemplate, 1, 1), ":") != 0 && strcmp(substr($this->mszTemplate, 0, 1), "\\") != 0 && strcasecmp(substr($this->mszTemplate, 0, 7), "http://") != 0) { Paul was right, the previous code was incorrect. But that didn't solve the problem. There is another problem, on line 102 with the realpath() php function (it always fails): $this->mszTemplate = realpath($szTemplatePath."/".$this->mszTemplate); Removing the realpath() function allows me to specify a http:// path to the legend template correctly, and allows me to specify a relative path (as long as it is relative to the template AND visible by the web browser). Can we live with this? Is there another option to realpath() ????? I can commit my 'fix', please let me know if i should or not.
to clarify: by "Is there another option to realpath()" I mean "Is there another function to use instead of realpath()?" I looked but couldn't find anything.
Jeff, there are a couple of new functions in the core of Chameleon now that can help resolve this problem. To use them: $oApp = GetChameleonApplication(); $szAbsPath = $oApp->resolvePathTo( $szRelPath, $_SESSION['gszAppPath'] ); this will create an absolute file system path from a relative path, relative to the application directory. If $szRelPath is absolute already, then it will be returned as is. If $szRelPath is a URL, it will be returned as is.
final fix is: if (isset($this->maParams["TEMPLATE"])) { $this->mszTemplate = trim($this->maParams["TEMPLATE"]); if (strtoupper(substr($this->mszTemplate, 0, 7)) == "HTTP://") { $aszFile = file($this->mszTemplate); $szTmpName = tempnam($_SESSION['gszTmpPath'], "legendtemplate").".html"; $fh = fopen($szTmpName, "w"); $nbLine = count($aszFile); for($i=0; $i<$nbLine; $i++) { fwrite($fh, $aszFile[$i]); } fclose($fh); $this->mszTemplate = $szTmpName; } else { $oApp= GetChameleonApplication(); $this->mszTemplate = $oApp->resolvePath2( $this->mszTemplate, $_SESSION['gszAppPath'] ); } }
Changing Version to 1.99 (2.0 not being worked on yet).
the fix works for http:// paths but not for relative paths. so the problem has to do with the else: else { $oApp= GetChameleonApplication(); $this->mszTemplate = $oApp->resolvePath2( $this->mszTemplate, $_SESSION['gszAppPath'] ); } The problem is that $_SESSION['gszAppPath'] points to the path to chameleon.php, not to the path to the template...see below for an example: $this->mszTemplate ===========> ./sample_legend_template.html $_SESSION['gszAppPath'] ==========> C:\ms4w\apps\chameleon\cwc2\htdocs therefore the function resolvePath2 in chameleon.php returns ======> C:\ms4w\apps\chameleon\cwc2\htdocs/sample_legend_template.html (where it actually lies in C:\ms4w\apps\testapp\ or http://127.0.0.1/testapp/ ) More details: I'm using the service instance of chameleon. I need my TEMPLATE file to reference a legend template file relative to the location of the template file. I believe this would be a common demand.... paul are u following me on this? i'm wondering if u have to parse [gszAppWebPath] to get the TEMPLATE path only and then concatonate that with $this->mszTemplate....anyway i'm out of my league, please help.
i'm guessing this problem only happens for the service instance..where $_SESSION['gszAppPath'] points to the chameleon/cwc2 folder (not chameleon.php as i wrote above) still it needs to be resolved.
um. I see the problem and there isn't a quick solution. Basically, Chameleon needs to find that file in a different location depending on whether the app is the service instance or a local app using the chameleon API. The problem is that in the service instance mode, there is no way to tell chameleon where to search relative to. I've modified cwc2.php and LegendTemplate.widget.php to attempt to work around this issue. It is now necessary for cwc2 to preserve the URLs to the remote templates that it was invoked with (previously they were just cached locally) and to provide a method for getting the current template. The LegendTemplate now checks to see if the main application object is a ServiceInstanceApp and will attempt to find templates relative to the current application template's URL if appropriate. Fixed code is in Jeff's hands for testing and committing to cvs.
verified for both http and relative path instances. nice work paul. committed cwc2.php and legendtemplate.widget.php fixes into CVS.