I've made a change to the build of the variable $query to exclude hidden items:
$query = sprintf('
SELECT
[GalleryItem::id],
[GalleryEntity::modificationTimestamp],
((%s - [GalleryEntity::creationTimestamp]) /
[GalleryEntity::serialNumber]) as SecondsPerChange
FROM
[GalleryItem]
INNER JOIN [GalleryEntity] ON [GalleryItem::id] = [GalleryEntity::id]
INNER JOIN [GalleryAccessSubscriberMap]
ON [GalleryItem::id] = [GalleryAccessSubscriberMap::itemId]
LEFT OUTER JOIN [GalleryItemHiddenMap]
ON [GalleryItem::id] = [GalleryItemHiddenMap::itemId]
%s
WHERE
%s
[GalleryAccessSubscriberMap::accessListId] IN (%s)
AND
[GalleryItemHiddenMap::itemId] is null
ORDER BY [GalleryEntity::modificationTimestamp] ASC
I also added some code for "protected"/private albums. Basically any album you don't want to appear in the sitemap. I do use url rewrite so this code will need to be adapted if you don't use it so that it will identify the albums by ID. Problem with this latter approach is that you must add all the sub-sub-sub-albums to the list which can get ugly. Using url rewrite however allows you to completelly eliminate an album and all it's sub albums. The urls are of the form site/v/album/blabla and the code looks for /album/. Usage: edit the array and add your albums there. On linux, this is case sensitive. On windows, I don't know.
$frequencyTable = array(
3600 => 'hourly',
24 * 3600 => 'daily',
7 * 24 * 3600 => 'weekly',
30 * 24 * 3600 => 'monthly',
365 * 24 * 3600 => 'yearly');
$i = 0;
$protectedAlbums = array('your_private_album_here', 'anotherone_here'); // ciuly
while ($result = $searchResults->nextResult()) {
if (($i++ % 100) == 0) {
$gallery->guaranteeTimeLimit(200);
}
$loc = $urlGenerator->generateUrl(
array('view' => 'core.ShowItem', 'itemId' => $result[0]),
array('forceSessionId' => false, 'forceFullUrl' => true));
$lastmod = gmstrftime('%Y-%m-%dT%H:%M:%S+00:00', $result[1]);
$changefreq = 'never';
foreach ($frequencyTable as $comparison => $value) {
if ($result[2] <= $comparison) {
$changefreq = $value;
break;
}
}
$protAlbum = 0;// ciuly start
while (($protAlbum<count($protectedAlbums)) && (strpos($loc, '/'.$protectedAlbums[$protAlbum].'/')===false)){
$protAlbum++;
}// ciuly end
if ($protAlbum==count($protectedAlbums)){// ciuly - condition
printf('<url><loc>%s</loc><lastmod>%s</lastmod><changefreq>%s</changefreq></url>',
$loc, $lastmod, $changefreq);
print "\n";
}
}