Gallery is the best Open Source Photo Album Interface and you can get it for free from http://gallery.menalto.com/
Presently i am talking about hacking into Gallery 2.3 . The same hack should work for previous versions of Gallery
What Gallery Has For SEO?
Gallery 2 comes with a URL Rewrite Module which can generate pretty search engine friendly URLS for albums and images.
What Gallery Lacks ?
Gallery has too many dirty Urls. By dirty urls i meant urls which have an = and ? symbol in them.. (eg: http://yoursite.com/main.php?g2_page=3). Secondly it has got this main.php thing everywhere..
So How are we going to hack into it?
We will try to convert these dirty urls into neat ones.. We will convert some of them and we will add the nofollow tag to the rest of them..
1)Hack to Remove main.php from almost everywhere
First of all goto your gallery installation folder and rename index.php to index.old.php . Now make a copy of main.php and save it as index.php so that both main.php and index.php exists.Now in your installation folder you will find a file named config.php. Open that up and you will find a line which defines
$gallery->setConfig(’baseUri’, ’something here’);
Replace this line with
$gallery->setConfig(’baseUri’, ‘http://www.yoursite.com/photos/’);
Here i assumed that http://www.yoursite.com/photos/ is your gallery url
Now your main.php thing should be gone.(Note: You might need to clear the template caches and all for the changes to take effect.You can do this from the Maintanance option in Site Admin. This thing is needed for many changes.. so do this every time u make changes..)
2)The Navigation Page SEO Hack
Now we will hack the paging system of Gallery 2.From this point i assume that you have installed and configured the URL Rewrite module of Gallery 2. Gallery has dirty page urls. the pages are referenced as g2_page=pagenumber So how are we going to hack it. We will change the degault paging to /page/pagenumber/ .I hope this will be a pretty good url..See a demo on my friend’s gallery
So how to do this..
a)Open up your .htaccess file in the gallery’s installation folder
Add this code to the beginning of the .htaccess file
RewriteEngine On
RewriteRule ^(.*)page/([0-9]+)/$ $1?g2_page=$2 [L]
Now the htaccess file will properly manage our neat page urls.
b)Now the rewrite module of Gallery should understand our hack.
So open up modules/rewrite/classes/RewriteSimpleHelper.class
you will see this code there
function loadItemIdFromPath() {
list ($path, $itemId) = GalleryUtilities::getRequestVariables(’path’, ‘itemId’);
if (!empty($path) && empty($itemId)) {
if (substr($path, -5) == ‘.html’) {
$path = substr($path, 0, -5);
}
list ($ret, $itemId) = GalleryCoreApi::fetchItemIdByPath($path);
if ($ret) {
return $ret;
}
GalleryUtilities::putRequestVariable(’itemId’, $itemId);
}return null;
}
We are adding some extra code here. Change this function to
function loadItemIdFromPath() {
list ($path, $itemId) = GalleryUtilities::getRequestVariables(’path’, ‘itemId’);
if (!empty($path) && empty($itemId)) {
if (substr($path, -5) == ‘.html’) {
$path = substr($path, 0, -5);}
$pattern = ‘/page(\/)(\d+)(\/)/i’;
$replacement = ”;
$path = preg_replace($pattern, $replacement, $path); list ($ret, $itemId) = GalleryCoreApi::fetchItemIdByPath($path);
if ($ret) {
return $ret;
}
GalleryUtilities::putRequestVariable(’itemId’, $itemId);
}return null;
}
Now our gallery can properly manage our hacked page navigation links..
c)Now we should generate the actual Neat Page Urls..For that we are going to tweak the file modules/core/classes/GalleryUrlGenerator.class
you will see a function function generateUrl($params=array(), $options=array())
in that function we have to add some extra code before the function’s last return statement(just before the last return $url; of this function)
$pattern = ‘/(\?)g2_page=1/i’;
$replacement = ”;
$url = preg_replace($pattern, $replacement, $url);$pattern = ‘/(\?)g2_page=(\d+)/i’;
$replacement = ‘page/$2/’;
$url = preg_replace($pattern, $replacement, $url);
d)Now the Page navigation hack is done..Clear the caches to see the changes..
3)Adding nofollow to other Dirty Urls
First of all download the NoFollow Addon for firefox Now from Firefox> Tools opt for Nofollow. Now you can see all nofollow links in pink colour.Our aim is to make all the dirty Urls to the pink colour.
You will see that the link login,sidebar etc have a dirty structure.. So edit modules/core/templates/blocks/SystemLinks.tpl and add rel=”nofollow” to appropriate a href tags.Similarly within your theme directory you will find files named theme.tpl,album.tpl and photo.tpl tweak them all with nofollow tags so that all of the dity Urls become pink..(like slideshow,add comment,view comments)
modules/core/templates/blocks/systemlinks.tpl change all to nofollow
modules/core/templates/blocks/breadcrump.tpl change all to nofollow
(Hey dont make the neat Urls as no follow by mistake.. if you unknowingly do so revert back..) .. Ok now got pink for all the dirty Urls?? then you are done.. and you are now having an SEO friendly Gallery 2
Hope that my tutorial helps you..If you find this information useful why not donate me something.it will help me to pay off my college fees.
If you like the post,it would be great if you can link to this post..