Adding FAlbum URLs to XML-Sitemap WordPress Plugin

As I mentioned on my previous post yesterday about Fixing FAlbum Plugin that I’m trying to add support for Google XML Sitemaps Plugin to FAlbum so that all URLs including albums, photos and tags would be added to Blog’s Sitemap which would be crawled by Google, Yahoo and MSN .
Actually, Google XML Sitemaps Plugin made the job much easier by providing simple WordPress add_action() to add the URLs, so you only need to add one function inside ‘wp-content/plugins/falbum/wordpress-falbum-plugin.php’ to accomplish the job !

Edit file wp-content/plugins/falbum/wordpress-falbum-plugin.php and add these lines before the add_action lines
copy code here

function addto_sitemaps(){
	global $falbum;
 
	#add FAlbum url to Sitemaps
	function FA_xml_url($pfx=''){
		if( ($FA_xml_go=&GoogleSitemapGenerator::GetInstance()) == null) return;
		$FA_xml_go->AddUrl( get_option('siteurl').$GLOBALS['falbum']->create_url($pfx) , time() , "always", 0.8);
	}
	#creates extra pages depending on the limit you set for 
	#photos and albums per page
	function FA_xml_pages($tot, $limit , $pfx = '' ){
	   $pages = ceil( $tot / $limit);
	   for($i=1; $i <= $pages; $i++)
			FA_xml_url(   $pfx.'page/'.$i.'/' );
	}
	#creates photos urls
	function FA_xml_get_photos(  &$photos , $pfx , $type = 'photoset'){
		global $falbum;
		$photo_title_array = array();
		for( $i=0, $max=count($photos[$type]['photo']); $i < $max ; $i++){
			$photo = $photos[$type]['photo'][$i];
			$photo_id = $photo['id'];
			$photo_title = $photo['title'];
 
			$photo_link = $falbum->_get_link_title($photo_title, $photo_id, $photo_title_array);
			$p = ceil(($i+1)/$falbum->options['photos_per_page']);
			FA_xml_url(  "{$pfx}page/{$p}/photo/{$photo_link}/");
		}
	}
	#disable administrator user_level to hide secret sets
	$GLOBALS['user_level'] = 0;
 
	#getting Flickr albums
	$albums = $falbum->_call_flickr_php('flickr.photosets.getList', array ("user_id" => $falbum->options['nsid']));
	#creating main album extra pages
	FA_xml_pages(  count($albums['photosets']['photoset']), $falbum->options['albums_per_page'] );
 
	#inserting recent photos pages
	$pfx = "show/recent/";
	FA_xml_url( $pfx);
	$photos = $falbum->_call_flickr_php('flickr.photos.search', array ('user_id' => $falbum->options['nsid'], 'sort' => 'date-taken-desc'));
 
	$num = count($photos);
	#get recent pages
	FA_xml_pages(   ($falbum->options['number_recent'] == -1 ? $num : $falbum->options['number_recent']) , $falbum->options['photos_per_page'] , $pfx);
	#get recent photos
	FA_xml_get_photos(   $photos , $pfx , 'photos');
 
	#to avoid creating duplicates when creating urls
	$photo_title_array = array();
	#creating albums urls
	foreach($albums['photosets']['photoset'] as $album){
		$id = $album['id'];
		$title = $falbum->_unhtmlentities($album['title']['_content']);
		$link_title = $falbum->_get_link_title($title, $id, $photo_title_array);
		$pfx = "album/{$link_title}/";
		FA_xml_url(  $pfx);
		#creating album extra pages
		FA_xml_pages(   $album['photos'] , $falbum->options['photos_per_page'] , $pfx);
 
		#getting album photos
		$photos = $falbum->_call_flickr_php('flickr.photosets.getPhotos', array ("photoset_id" => $album['id']));
		FA_xml_get_photos(   $photos , $pfx);
 
 
	}
 
 
	#inserting tags pages
	FA_xml_url(  "show/tags/");
	$tags = $falbum->_call_flickr_php('flickr.tags.getListUserPopular', array ('count' => '500', user_id => $falbum->options['nsid']));
 
	foreach( $tags['who']['tags']['tag'] as $tag ){
		$pfx = "tags/{$tag['_content']}/";
		FA_xml_url(  $pfx);
 
 
		#getting tag photos
		$photos = $falbum->_call_flickr_php('flickr.photos.search', array ('user_id' => $falbum->options['nsid'], 'tags' => $tag['_content'], 'tag_mode' => 'all'));
		$num = count($photos);
		#tag pages
		FA_xml_pages(   $num,  $falbum->options['photos_per_page'], $pfx);
 
		FA_xml_get_photos(   $photos , $pfx, 'photos');
 
	}
}
add_action("sm_buildmap","addto_sitemaps");

you see a working preview of my Sitemap

*update 10Dec2007 : fixed photo links 302 redirection*

Recommended posts:


Tags : add creates creating disable get getting inserting photos tag to

This entry was posted on Thursday, November 22nd, 2007 at 2:19 pm and is filed under Programs, Solutions. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

  • http://what-is-what.com/what_is/url.html What is a URL?

    Can the sitemap map things that are outside of WP? Photos, for instance?

  • http://gadelkareem.com wkarim

    @whatisaurl : it’s a question to ask xml-sitemaps plugin support. however, you can add static pages manually and you don’t need to add photos to sitemaps unless it’s for Google images search.

  • http://what-is-what.com/what_is/url.html What is a URL?

    The static pages won’t get overwritten when I update?

  • http://gadelkareem.com wkarim

    @whatisaurl : xml-sitemaps plugin store manually added static pages in the database so as far as you did not make any changes in the DB during the upgrade it will not change

  • http://mattapps.com Matt

    Hi! Whenever I paste your above script into wp-content/plugins/falbum/wordpress-falbum-plugin.php, it takes down my blog… running falbum 0.7.1 and sitemaps 3.0.3. Any suggestions? is it a pathing issue? (the blog sits at /blog, but it is actually at the root).

  • http://gadelkareem.com wkarim

    @Matt
    Please copy and paste the code again, or replace all unicode (’‘) with ‘

  • http://mattapps.com Matt

    Thanks, I’ll try– also, I didn’t do your other updates from your other post… is it necessary to do that as well, or can I just do this one?

  • http://gadelkareem.com wkarim

    @Matt
    Welcome! you don’t need to add the fixes from the other post for adding falbum to sitemap to work.

  • Pingback: Fixing Flickr FAlbum rewrite rules, thumbnails, javascripts and more … :: GadElKareem

  • http://www.hirwaun.net/ Coalman

    I am unable to cut + paste your code as it throws up unusual characters. I’ve tried visual browsers like Firefox and also Lynx.

    Can you please help ?

  • http://gadelkareem.com wkarim

    @coalman
    please use text file to copy your code

  • tamedcats

    Hi,

    I tried to add image but I don’t know how to do this
    Can anyone be kind to tell me how?

    thanks a lot


 Top