Topics

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, 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

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( _option('siteurl').$GLOBALS['falbum']->create_url($pfx) , time() , "always", 0.8);
	}
	# 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.'/' );
	}
	# photos urls
	function FA_xml__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->__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}/");
		}
	}
	# administrator user_level to hide secret sets
	$GLOBALS['user_level'] = 0;

	# Flickr albums
	$albums = $falbum->_call_flickr_php('flickr.photosets.getList', array ("user_id" => $falbum->options['nsid']));
	# main album extra pages
	FA_xml_pages(  count($albums['photosets']['photoset']), $falbum->options['albums_per_page'] );
	
	# 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  duplicates when  urls
	$photo_title_array = array();
	# 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);
		# 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'][''] as $ ){
		$pfx = "tags/{$['_content']}/";
		FA_xml_url(  $pfx);
		
		
		#getting  photos
		$photos = $falbum->_call_flickr_php('flickr.photos.search', array ('user_id' => $falbum->options['nsid'], 'tags' => $['_content'], '_mode' => 'all'));
		$num = count($photos);
		# 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*