forked from e107inc/e107
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgsitemap.php
More file actions
246 lines (182 loc) · 4.97 KB
/
Copy pathgsitemap.php
File metadata and controls
246 lines (182 loc) · 4.97 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
<?php
/*
* e107 website system
*
* Copyright (C) 2008-2009 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* Plugin supporting file - gsitemap
*
* $Source: /cvs_backup/e107_0.8/gsitemap.php,v $
* $Revision$
* $Date$
* $Author$
*
*/
require_once("class2.php");
if(!e107::isInstalled('gsitemap'))
{
e107::redirect();
exit();
}
e107::lan('gsitemap');
class gsitemap_xml
{
function __construct()
{
$items = [];
// Gsitemap Addon.
if(!empty($_GET['plug']) && !empty($_GET['func']))
{
if(!e107::isInstalled($_GET['plug']))
{
exit;
}
$obj = e107::getAddon($_GET['plug'], 'e_gsitemap');
if($items = e107::callMethod($obj, $_GET['func']))
{
$this->renderXML($items);
}
}
elseif(!empty($_GET['index'])) // Sitemap index.
{
$this->renderSitemapIndex();
}
else // From Gsitemap Database Table.
{
$this->renderXML();
}
}
/**
* @param $items
* @return void
*/
function renderXML($items=array())
{
header('Content-type: application/xml', TRUE);
$xml = "<?xml version='1.0' encoding='UTF-8'?>
<urlset xmlns='http://www.sitemaps.org/schemas/sitemap/0.9' xmlns:image='https://www.google.com/schemas/sitemap-image/1.1'>";
if(empty($items))
{
$smArray = e107::getDb()->retrieve("gsitemap", "*", "gsitemap_active IN (".USERCLASS_LIST.") ORDER BY gsitemap_order ",true);
$xml .= $this->renderXMLItems($smArray, 'gsitemap_');
}
else
{
$xml .= $this->renderXMLItems($items);
}
$xml .= "
</urlset>";
echo $xml;
}
function renderXMLItems($data, $prefix = '')
{
$tp = e107::getParser();
$xml = '';
foreach($data as $sm)
{
$url = $sm[$prefix.'url'];
if($url[0] === '/')
{
$url = ltrim($url, '/');
}
$loc = (strpos($url, 'http') === 0) ? $url : SITEURL.$tp->replaceConstants($url,true);
$xml .= "
<url>
<loc>".$loc."</loc>";
if(!empty($sm[$prefix.'image']))
{
$imgUrl = $sm[$prefix.'image'];
if($imgUrl[0] === '/')
{
$imgUrl = ltrim($imgUrl, '/');
}
$imgUrl = (strpos($imgUrl, 'http') === 0) ? $imgUrl : SITEURL.$tp->replaceConstants($imgUrl,true);
$xml .= "
<image:image>
<image:loc>".$imgUrl."</image:loc>
</image:image>";
}
$xml .= "
<lastmod>".date('c', (int) $sm[$prefix.'lastmod'])."</lastmod>
<changefreq>".$sm[$prefix.'freq']."</changefreq>
<priority>".$sm[$prefix.'priority']."</priority>
</url>";
}
return $xml;
}
/**
* Generates a Sitemap Index containing references to multiple sitemaps.
*
* @param array $sitemaps An array of sitemaps, where each item is an associative array with keys:
* - 'loc' (string): The full URL of the sitemap.
* - 'lastmod' (int|null): A timestamp representing the last modification date of the sitemap (optional).
* @return void
*/
function renderSitemapIndex()
{
header('Content-type: application/xml', true);
// Begin the sitemap index
$xml = "<?xml version='1.0' encoding='UTF-8'?>\n";
$xml .= "<sitemapindex xmlns='http://www.sitemaps.org/schemas/sitemap/0.9'>\n";
$obj = e107::getAddon('gsitemap', 'e_url');
$sitemaps = [];
if($items = e107::callMethod($obj, 'config'))
{
foreach($items as $key => $val)
{
if($key == 'sitemaps' || $key == 'index')
{
continue;
}
$sitemaps[] = ['loc' => e107::url('gsitemap',$key, null, ['mode'=>'full']), 'lastmod' => (time() - 86400)];
}
}
foreach($sitemaps as $sitemap)
{
$xml .= "<sitemap>\n";
$xml .= "\t<loc>{$sitemap['loc']}</loc>\n";
if(!empty($sitemap['lastmod'])) // Optional: Include the last modified date, if available
{
$xml .= "\t<lastmod>" . date('c', (int) $sitemap['lastmod']) . "</lastmod>\n";
}
$xml .= "</sitemap>\n";
}
$xml .= "</sitemapindex>";
// Output the XML
echo $xml;
}
}
// HTML below.
if(e_QUERY == "show" || !empty($_GET['show']))
{
e107::canonical('gsitemap');
e107::route('gsitemap/index');
require_once(HEADERF);
$nfArray = e107::getDb()->retrieve("gsitemap", "*", "gsitemap_active IN (".USERCLASS_LIST.") ORDER BY gsitemap_order ",true);
$tp = e107::getParser();
if(deftrue('BOOTSTRAP'))
{
$bread = array(
0 => array('text' => $tp->toHTML(GSLAN_Name), 'url'=> null ) // e107::url('gsitemap','index')
);
$text = e107::getForm()->breadcrumb($bread);
e107::breadcrumb($bread);
}
else
{
$text = '';
}
$text .= "<div style='text-align:left' class='gsitemap'><ul>";
foreach($nfArray as $nfa)
{
$url = (substr($nfa['gsitemap_url'],0,4)== "http")? $nfa['gsitemap_url'] : SITEURL.$tp->replaceConstants($nfa['gsitemap_url'],TRUE);
$text .= "<li>".$tp->toHTML($nfa['gsitemap_cat'],"","defs").": <a href='".$url."'>".$tp->toHTML($nfa['gsitemap_name'],"","defs")."</a></li>\n";
}
$text .= "</ul></div>";
e107::getRender() -> tablerender(GSLAN_Name, $text);
require_once(FOOTERF);
exit;
}
new gsitemap_xml;