forked from dmitryd/typo3-dd_googlesitemap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.tx_ddgooglesitemap_generator.php
115 lines (104 loc) · 2.74 KB
/
class.tx_ddgooglesitemap_generator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
/***************************************************************
* Copyright notice
*
* (c) 2007-2014 Dmitry Dulepov <[email protected]>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* This class is a base for all sitemap generators.
*
* @author Dmitry Dulepov <[email protected]>
*/
abstract class tx_ddgooglesitemap_generator {
/**
* cObject to generate links
*
* @var tslib_cObj
*/
protected $cObj;
/**
* Maximum number of items to show.
*
* @var int
*/
protected $limit;
/**
* Offset to start outputting from.
*
* @var int
*/
protected $offset;
/**
* A sitemap renderer
*
* @var tx_ddgooglesitemap_abstract_renderer
*/
protected $renderer;
/**
* Class name to instantiate the renderer.
*
* @var string
*/
protected $rendererClass = 'tx_ddgooglesitemap_normal_renderer';
/**
* Initializes the instance of this class. This constructir sets starting
* point for the sitemap to the current page id
*/
public function __construct() {
$this->cObj = t3lib_div::makeInstance('tslib_cObj');
$this->cObj->start(array());
$this->offset = max(0, intval(t3lib_div::_GET('offset')));
$this->limit = max(0, intval(t3lib_div::_GET('limit')));
if ($this->limit <= 0) {
$this->limit = 50000;
}
$this->createRenderer();
}
/**
* Writes sitemap content to the output.
*
* @return void
*/
public function main() {
header('Content-type: text/xml');
if ($this->renderer) {
echo $this->renderer->getStartTags();
}
$this->generateSitemapContent();
if ($this->renderer) {
echo $this->renderer->getEndTags();
}
}
/**
* Creates the renderer using $this->rendererClass. Subclasses can use a
* more flexible logic if just setting the class is not enough.
*
* @return void
*/
protected function createRenderer() {
$this->renderer = t3lib_div::makeInstance($this->rendererClass);
}
/**
* Generates the sitemap and echoes it to the browser.
*
* @return void
*/
abstract protected function generateSitemapContent();
}