Working transliterated SEF links for JoomGallery via router.php and compatibility with JoomFish
On the Joomla! sites I build, I use the JoomGallery component — even though it's not MVC, it's quite feature-rich, easy to configure, and works well. Until recently, I couldn't get SEF URLs working for the gallery.
I don't use SEF components, because with sh404SEF you still have to hunt for plugins to get proper links, so the advantage over the standard SEF is small, and I never managed to figure out Artio JoomSEF — both times I installed it, errors started cropping up whose cause I couldn't understand, plus these components are paid, although that's not a problem. If someone specifically requires one of these components on a site, then I'll go ahead and install it and figure it out, but right now they take up too much time, I don't like things that are this buggy.
Of course, I immediately found this thread; the router.php posted there is suitable for English-language sites, and it works for Russian ones too, only the links come out with letters of the language the site is in. And they end up with uppercase letters in them, which still isn't pretty and can cause problems in some browsers and when passing links around — I can't call such links friendly.
Yes, a solution to the problem was suggested there, by adding a letter-replacement function, but after that my gallery stopped working — I don't know whether it kept working for others. Because then the links are created the way they should be, the names get transliterated and everything is fine with the addresses, but these addresses lead nowhere, since the script itself takes the category or photo name from the address and then searches the database for a category with the same name, but in the database the categories are recorded in Russian, while in the addresses they're already transliterated, so all the links lead to the root of the gallery.
Because of this, I used the gallery on sites without pretty links, and there was no need to optimize the gallery anyway — the main emphasis was always placed on the texts. During the week I found some free time and was in the mood to figure out router.php. In the end, I changed the logic for finding the matching category in the address a bit: I made it read from the database the whole list of category or photo names that match, then transliterated each name and compared it to the one I needed, and that way I could determine the right category or photo IDs. For this I wrote an additional function and added it after the modified database queries — yes, such a script consumes a bit more resources and takes longer to run, but for Joomla that's not a problem, if you compare it with the voraciousness of the core and the rest of the stuff.
When I copied the resulting router.php to a multilingual site running JoomFish, another problem turned up. The database queries already returned translated category and photo names, so they couldn't be matched against the names from the links. But this was solved easily. Since JoomFish overrides the database-access methods, in the script itself I added arguments to the queries of these methods indicating that translation isn't needed, and in the end everything worked. It may not be pretty that on the English version of the site the paths contain Russian transliterated names, but it's unlikely this can be fixed easily, plus in the other components with paths it's the same way.
You can download the new router.php for JoomGallery via this link. The script's code isn't perfect, but it works.
You can see the results of its work here: http://mebelok.com.ua/gallery (the first site I tested it on; since the photo names repeat, I added the ID to the addresses, so the matching photos are looked up not by name); http://bizukov.org.ua/ru/photo (a multilingual site, the IDs aren't output to the photo addresses, so you can fully verify how it works).