10 May 2005 - 22:31Mambo and Gallery SEF URLs With Fix
While using the Gallery project embedded in Mambo, it does not correctly respect the SEF URL parameter in the configuration file. Some of the URLs can’t be represented in the SEF URL syntax, because they point to the actual Gallery location. These are mostly the administration functions such as adding and removing pictures. The navigation and picture display, however, are controlled completely through the Mambo embedded component. After digging through the Mambo SEF code in a previous problem, I know that the SEF URL is converted correctly into the corresponding $_GET and $_REQUEST parameters, so therefore, they should not interfere with the operation of the gallery pages. This can be verified by manually converting the link. Fortunately I found a simple and elegant patch to fix the problem. Read on for the solution.
NOTE: This refers to a very old Mambo version. This is for information purposes only.
Problem
The problem occurs because the URLs are not being passed to the sefRelToAbs(…) function located inside /includes/sef.php , or if they are, they are not in the correct format. Similar behavior can be seen with the Mambo RSS SEF URL bug. The other interesting thing to note is that there is already Mambo specific code inside Gallery so that sticking in some more custom code won’t hurt things.
Most OSS projects have some type of URL alteration function, so we have to find it in Gallery. Looking at any of the gallery include files we can easily see that the function is called makeGalleryUrl(…) . Searching a little further we find it in lib/url.php on line 18.
Reviewing this function, we can see that it uses the $GALLERY_EMBEDDED_INSIDE and $GALLERY_EMBEDDED_INSIDE_TYPE variables to determine if we’re inside another project. This is where we see the Mambo URL building. Lower down the function, however, we don’t see the special sefRelToAbs(…) function. Instead, the URL is built and then returned on line 129.
Solution
The easiest solution is to add another switch/case statement to determine if we’re inside Mambo, and then call our sefRelToAbs(…) function to set a new return value. This changes something like this:
return htmlspecialchars($url);
Into something like this:
$retVal = '';
if( isset($GALLERY_EMBEDDED_INSIDE)) {
switch ($GALLERY_EMBEDDED_INSIDE_TYPE) {
case 'mambo':
if(function_exists('sefRelToAbs')) {
// Since there's no way to convert the gallery
// url's just the embedded mambo links,
// and since gallery uses the notation
// /index..... instead of just index.php, we'll
// strip off the leading slash.
$url = preg_replace('/^\//', '', $url);
//error_log("Trying to convert: ".$url);
$retVal = sefRelToAbs($url);
}
else {
$retVal = htmlspecialchars($url);
}
break;
default:
$retVal = htmlspecialchars($url);
}
}
return $retVal;
WARNING: You should not attemt to use this text here to manually edit the url.php file. Instead you should use the patchfile with the patch command since that will always contain the most current version of the changes. It is also a much smaller chance of making an error. If you must edit the file by hand, consult the patchfile for the exact lines that are added and removed.
If you notice, we need the preg_replace because the links that are passed to Mambo are in the form /index.php?param=value instead of just index.php?param=value . With the leading slash, Mambo won’t touch the URL. URL’s for the Gallery administration tools are not touched since they are fully qualified URLs.
The other important thing to notice is the check if the SEF function was defined. There seems to be a problem where the administrator functions are opened in a new page in a Gallery only URL. This means the Mambo include files are not included, but Gallery reports as being embedded in Mambo. This gives us a final patch file here.
Conclusion
This problem is just one more of the small problems where project standards aren’t followed. This Mambo standard doesn’t affect the overall functionality so it was probably ignored, but it’s something that I would like to add. The good thing about this fix is that it uses the standard Mambo SEF URLs. This way, SEF URL plug-ins that make URLs even more readable, will seamlessly plug-in with this fix. Hopefully I can come up with something like that on my own. Hope this helps some.
Related Articles
- Mambo XHTML Compliant Bug
- Mambo PHP Error Messages With Fix
- The Patch Command and OSS
No Comments | Tags: Programming