~ubuntu-branches/ubuntu/lucid/gallery2/lucid

« back to all changes in this revision

Viewing changes to modules/sitemap/Sitemap.inc

  • Committer: Bazaar Package Importer
  • Author(s): Michael C. Schultheiss
  • Date: 2006-04-16 16:42:35 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060416164235-8uy0u4bfjdxpge2o
Tags: 2.1.1-1
* New upstream release (Closes: #362936)
  + Bugfixes for Postgres7 (Closes: #359000, #362152)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/*
 
3
 * $RCSfile: Sitemap.inc,v $
 
4
 *
 
5
 * Gallery - a web based photo album viewer and editor
 
6
 * Copyright (C) 2000-2006 Bharat Mediratta
 
7
 *
 
8
 * This program is free software; you can redistribute it and/or modify
 
9
 * it under the terms of the GNU General Public License as published by
 
10
 * the Free Software Foundation; either version 2 of the License, or (at
 
11
 * your option) any later version.
 
12
 *
 
13
 * This program is distributed in the hope that it will be useful, but
 
14
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
 * General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU General Public License
 
19
 * along with this program; if not, write to the Free Software
 
20
 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA.
 
21
 */
 
22
 
 
23
/**
 
24
 * @version $Revision: 1.3 $ $Date: 2006/01/13 03:39:51 $
 
25
 * @package Sitemap
 
26
 * @subpackage UserInterface
 
27
 * @author Bharat Mediratta <bharat@menalto.com>
 
28
 */
 
29
 
 
30
/**
 
31
 * Create an appropriate Google Sitemap for this site.
 
32
 *
 
33
 * @package Sitemap
 
34
 * @subpackage UserInterface
 
35
 */
 
36
class SitemapView extends GalleryView {
 
37
 
 
38
    /**
 
39
     * @see GalleryView::isImmediate
 
40
     */
 
41
    function isImmediate() {
 
42
        return true;
 
43
    }
 
44
 
 
45
    /**
 
46
     * @see GalleryView::renderImmediate
 
47
     */
 
48
    function renderImmediate($status, $error) {
 
49
 
 
50
        list ($ret, $rootId) =
 
51
            GalleryCoreApi::getPluginParameter('module', 'core', 'id.rootAlbum');
 
52
        if ($ret) {
 
53
            return $ret->wrap(__FILE__, __LINE__);
 
54
        }
 
55
 
 
56
        $ret = $this->renderSitemap($rootId);
 
57
        if ($ret) {
 
58
            return $ret->wrap(__FILE__, __LINE__);
 
59
        }
 
60
    }
 
61
 
 
62
    /**
 
63
     * Output a site map rooted at the given id
 
64
     *
 
65
     * @param the root id
 
66
     * @return object GalleryStatus a status code
 
67
     */
 
68
    function renderSitemap($rootId) {
 
69
        global $gallery;
 
70
        $urlGenerator =& $gallery->getUrlGenerator();
 
71
        $phpVm = $gallery->getPhpVm();
 
72
 
 
73
        /*
 
74
         * Ideas:
 
75
         *  - Calculate priority by using a percentage of item view count to max view counts
 
76
         */
 
77
 
 
78
        /*
 
79
         * Don't use a template for this as we may wind up trying to buffer
 
80
         * way too much data
 
81
         */
 
82
        $phpVm->header('Content-type: application/xhtml+xml');
 
83
        print '<?xml version=\'1.0\' encoding=\'UTF-8\'?>';
 
84
        print "\n";
 
85
        print '<urlset xmlns="http://www.google.com/schemas/sitemap/0.84" ';
 
86
        print 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ';
 
87
        print 'xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84 ';
 
88
        print 'http://www.google.com/schemas/sitemap/0.84/sitemap.xsd">';
 
89
        print "\n";
 
90
 
 
91
        $queue = array($rootId);
 
92
        while (!empty($queue)) {
 
93
            $currentId = array_shift($queue);
 
94
            list ($ret, $newIds) =
 
95
                GalleryCoreApi::fetchChildItemIdsWithPermission($currentId, 'core.view');
 
96
            if ($ret) {
 
97
                return $ret->wrap(__FILE__, __LINE__);
 
98
            }
 
99
            $queue = array_merge($queue, $newIds);
 
100
 
 
101
            /* TODO: load entities in chunks */
 
102
            list ($ret, $entity) = GalleryCoreApi::loadEntitiesById($currentId);
 
103
            if ($ret) {
 
104
                return $ret->wrap(__FILE__, __LINE__);
 
105
            }
 
106
 
 
107
            printf("<url><loc>%s</loc><lastmod>%s</lastmod></url>\n",
 
108
                   $urlGenerator->generateUrl(
 
109
                       array('view' => 'core.ShowItem', 'itemId' => $currentId),
 
110
                       array('forceSessionId' => false, 'forceFullUrl' => true)),
 
111
                   substr_replace(
 
112
                       gmstrftime("%Y-%m-%dT%H:%M:%S%z", $entity->getModificationTimestamp()),
 
113
                       ":", -2, 0));
 
114
        }
 
115
        print '</urlset>';
 
116
 
 
117
        return null;
 
118
    }
 
119
}
 
120
?>