Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/* vim: set noai expandtab ts=4 st=4 sw=4: */
3
 
4
/**
5
 * Generate sitemap index file.
6
 *
7
 * PHP versions 5
8
 *
9
 * Redistribution and use in source and binary forms, with or without
10
 * modification, are permitted provided that the following conditions are met:
11
 *
12
 *  * Redistributions of source code must retain the above copyright notice,
13
 *    this list of conditions and the following disclaimer.
14
 *  * Redistributions in binary form must reproduce the above copyright notice,
15
 *    this list of conditions and the following disclaimer in the documentation
16
 *    and/or other materials provided with the distribution.
17
 *  * The names of its contributors may not be used to endorse or promote
18
 *    products derived from this software without specific prior written
19
 *    permission.
20
 *
21
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
 * POSSIBILITY OF SUCH DAMAGE.
32
 *
33
 * @category File
34
 * @package  File_Sitemap
35
 * @author   Charles Brunet <cbrunet@php.net>
36
 * @license  http://www.opensource.org/licenses/bsd-license.html BSD License
37
 * @version  CVS: $Id: Index.php 299129 2010-05-07 22:21:04Z cbrunet $
38
 * @link     http://pear.php.net/package/File_Sitemap
39
 */
40
 
41
require_once "File/Sitemap/Base.php";
42
 
43
/**
44
 * Generate sitemap index file.
45
 *
46
 * @category File
47
 * @package  File_Sitemap
48
 * @author   Charles Brunet <cbrunet@php.net>
49
 * @license  http://www.opensource.org/licenses/bsd-license.html BSD License
50
 * @version  Release: 0.1.3
51
 * @link     http://pear.php.net/package/File_Sitemap
52
 */
53
class File_Sitemap_Index extends File_Sitemap_Base
54
{
55
 
56
    /**
57
     * URL of XML schema
58
     */
59
    const SCHEMA = 'http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd';
60
 
61
    /**
62
     * Constructor.
63
     *
64
     * @return void
65
     */
66
    public function __construct()
67
    {
68
        parent::__construct('sitemapindex', self::SCHEMA);
69
    }
70
 
71
    /**
72
     * Add a sitemap to the sitemapindex.
73
     *
74
     * @param mixed $loc     string | array. URL (or array of URL) of the
75
     *    sitemap file.
76
     * @param mixed $lastmod Date (and time) of last modification (optional).
77
     *
78
     * @return void
79
     */
80
    public function add($loc, $lastmod = null)
81
    {
82
        if (!is_array($loc)) {
83
            $loc = array($loc);
84
        }
85
 
86
        foreach ($loc as $l) {
87
            // normalize and encode $loc
88
            $l = $this->parseURL($l);
89
 
90
            // look for this url into the dom tree
91
            $sitemap = $this->findLoc($l);
92
            if ($sitemap === false) {
93
                // Create the url node, and append loc node
94
                $sitemap = $this->dom->createElementNS(self::XMLNS, 'sitemap');
95
 
96
                $elemLoc = $this->dom->createElementNS(self::XMLNS, 'loc', $l);
97
                $sitemap->appendChild($elemLoc);
98
                $newURL = true;
99
            } else {
100
                $newURL = false;
101
            }
102
 
103
            if ($lastmod !== null) {
104
                $lastmod = $this->_parseDateTime($lastmod);
105
                $this->updateNode($sitemap, 'lastmod', $lastmod);
106
            }
107
 
108
            $this->dom->documentElement->appendChild($sitemap);
109
        }
110
    }
111
 
112
    /**
113
     * Validate sitemap index with the schema definition.
114
     *
115
     * @return boolean
116
     */
117
    public function validate()
118
    {
119
        return parent::validate(self::SCHEMA);
120
    }
121
 
122
}
123
 
124
?>