2 June 2005 - 22:43Mambo, Xaneon, and Gallery SEF Extension
Lately I started using the Xaneon Extensions component for Mambo to generate nicer URL’s for my site. The typical /content/view/28/31/ links were starting to irritate me, and I knew there had to be a better way. Not only that, but after digging through the code on my last projects, I noticed that the simple existence of the file components/com_sef/sef.php will cause that to be used instead of traditional includes/sef.php file. This means that the whole Search Engine Friendly capability can be achieved by installing a specifically named component. After looking around I found the Xaneon Extensions project which seemed best because it used this component style SEF ability and it also seemed to have the most features. No modifications to existing sources was impressive too. The one problem I had after using it is that there is no support for the Gallery component. Therefore all the Gallery URL’s take the form /component/ option,com_gallery/ Itemid,28/ set_albumName,73nova/ include,view_album.php/ if my Gallery component fix is used, and even worse, /index.php?option=com_gallery& Itemid=28& set_albumName=73nova& include=view_album.php if my fix is not used. Therefore, I decided to look at the possible solutions and came up with my own Gallery Xaneon Extension and Pathway fix. Both are inspired from the LogicX solution with fixes and design improvements. Read on for the details.
NOTE: This refers to a very old Mambo version. This is for information purposes only.
SEF Problem
After installing and setting up the Xaneon Extensions component, the Gallery component doesn’t produce Search Engine Friendly URL’s. The solution produced by LogicX basically works, but it goes against what I consider to be a good design. The solution is tightly coupled to the site using the mod_rewrite tool. If there is a need to specifically disable the component, editing the rewrite rules is the only way. If the URL structure changes in Gallery, it becomes difficult to impossible to check for the Gallery version and alther the URL accordingly. It also severely restricts modifiability by hard coding per installation variables in the rewrite rules.
I dug through the Xaneon code and was very impressed that they provided a framework for extending the SEF capabilities. I was disappointed by the lack of documentation, but I managed to figure out the framework and come up with some code.
SEF Solution
First, before the Gallery URL’s can even be touched, my previous fix is needed to process the Gallery URL’s through Mambo. This is best described in my other article about the Gallery SEF Fix. Essentially it forces Gallery to use the Mambo sefRelToAbs(…) function so that Mambo can alter the URL’s. This patch must be run from the gallery folder, not the Mambo folder.
Second, you have to rename the actual gallery location to something other than the SEF one. My actual gallery location was located in /gallery/ but that’s what I wanted to use as my Mambo gallery. This means that I had to rename the actual gallery folder to /mygallery/. IMPORTANT: You must go through the gallery setup again after you move gallery to the new location. Otherwise things will not work correctly.
Now that we can alter the Gallery URL’s, we have to check how Xaneon handles the extensions. This was the most difficult part because of the lack of documentation. It’s not so simple as it looks. To create a SEF extension, the following conditions must be met:
- The extension name must match the name of the component. In this case I’ll use mycomp as the name of the component and com_mycomp is the folder where the component resides. For my gallery component located in com_gallery the component name is gallery.
- The extension file must be located in administrator/components/com_sef/extensions/ and it must be called sef_ext.mycomp.php .
- There must be a class named sef_gallery defined the file.
- The class must implement two functions, string create(string) and string revert(array,int) .
- The components link must be setup in the Mamabo administration page and the link name must not be named the same as a real folder in the mambo installation. In my example, it is required that you rename the actual gallery to something other than what you are going to use as the component link name.
- The PHP file must contain no errors, or they will kill your page and it will not finish loading. You will receive no warning or error messages.
Only after all these conditions are met, and the two extension functions are implemented will the page actually load and accurately translate URL’s. The two functions are essentially total opposites of each other. The create function is used to generate the SEF URL from a URL such as /index.php?option=com_gallery&Itemid=28&… and turn it into something meaningful. The returned string will be prefixed with the component link given in the admin page. In my case, if you return album/image it will display /gallery/album/image on the page, where gallery is my component link.
The revert function is used to convert the URL back to it’s /index.php?option=com_gallery&Itemid=28&… form. The good news is that you don’t have to determine the component link yourself or find out the menu Itemid parameter. You simply have to tack on the extra parameters after the option and Itemid parameters.
The one thing that may not be initially apparent while looking over these two functions is that all data to encode/decode a URL must be passed within the SEF portion. Therefore, generating a URL on any non-unique string will cause problems since decoding the URL could have multiple possibilities going back.
For my Gallery extension I found it sufficient using the album name and image name as two unique pieces of information. First they are already inside the URL string and second, if there is no album it must be the front page, if there is no image it must be an album, and if there is an album and image, then it must be an image. That way the Gallery parameter of what PHP file to include can be found by identifying the correct situation.
Pathway Problem
One thing I know a bunch of people really like is the pathway feature that Mambo provides with the breadcrumb links showing how to get out of where you are. The problem is how the pathway is setup. Looking through the includes/pathway.php file you see what is happening. First it always adds a Home link. Second, if you have clicked on an item on the menu, that will be shown second. That’s all for the basic pathway functionality. Although I’m sure this design worked well on the first write up, now the design is holding people back. The problem is that if someone clicks on a menu item that in this example shows an article. Rather than having the pathway show Home > Article Name the Section and Category should be stuck between the two. This is what that huge switch statement does inside the pathway function. Ever special case that needs a different pathway needs to have its code stuck in this file. This is a pretty bad design and I hope it gets fixed, but there’s nothing we can do about that for now. The one thing that we can do, is at the very bottom of the function they have provided us the ability to append to the pathway.
Pathway Solution
Since throughout the whole gallery we only see Home > Gallery and we only need to append pathway links to it, we can use the mosMainFrame::appendPathWay(string) function. This will append the given string to the pathway. When it is called multiple times, each string is appended after the previous.
Since we’re working on getting things more integrated, we can also toss in some calls to mosMainFrame::setPageTitle(string) and mosMainFrame::appendPathWay(string). The first will set the title of the browser window and the second will append the HTML to the pathway. This code is the LogicX solution that has been fixed.
Conclusion
After applying the Gallery SEF Fix, and adding the Xaneon extension to Mambo, Gallery can produce impressive URLs. This can be customized even further with the pathway and page title fix. This solution is clean and elegant. The Gallery SEF patch does not produce any negative side effects, and will correctly obey the SEF parameter in Mambo. The Xaneon extension can be disabled totally and embedded Gallery URLs will return to normal or the component extension can be disabled to produce the same effect. Each of these can be performed from the administration page.
I should note that although the Gallery SEF patch and the pathway patch are generic and can be used without additional software, the extension must be used with Xaneon. Although this was an upside to me, it could be a downside for others. If you can not use Xaneon and wish to achieve the same effect, you should consider the mod_rewrite rules by LogicX.
Files:
No Comments | Tags: Programming