-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsitemap.php
More file actions
98 lines (87 loc) · 2.45 KB
/
sitemap.php
File metadata and controls
98 lines (87 loc) · 2.45 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
<?
class sitemap{
function __construct($domain,$directory){
if(!empty($domain) && !empty($directory) ){
$this->domain = $domain;
$this->directory = $directory;
}else{
return false;
}
}
function generateSitemap($array,$type){
$i=1;
foreach($array as $sitemap){
$temp = $this->sitemapStart();
if($type==1){
foreach($sitemap as $result){
$temp .= '<url>';
$temp .= "\n";
$temp .= '<loc>http://'.$this->domain.'/films/'.$this->safeurl($result['Naam']).'/'.$result['ID'].'/</loc>';
$temp .= "\n";
$temp .= '</url>';
$temp .= "\n";
}
}
if($type==2){
foreach($sitemap as $result){
$temp .= '<url>';
$temp .= "\n";
$temp .= '<loc>http://'.$this->domain.'/films-nieuws/'.$result['id'].'/'.$this->safeurl($result['titel']).'/</loc>';
$temp .= "\n";
$temp .= '</url>';
$temp .= "\n";
}
}
$temp .= $this->sitemapEnd();
if($type==1){
$this->saveSitemap($temp, ''.$this->directory.'/sitemapmovies'.$i.'.xml');
}
if($type==2){
$this->saveSitemap($temp, ''.$this->directory.'/sitemapnieuws'.$i.'.xml');
}
unset($temp,$sitemap);
$i++;
}
}
function sitemapStart(){
$xml = '<?xml version="1.0" encoding="UTF-8"?>';
$xml .= "\n";
$xml .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">';
$xml .= "\n";
return $xml;
}
function sitemapEnd(){
$xml = '</urlset>';
return $xml;
}
function saveSitemap($data,$filename){
file_put_contents($filename, $data);
}
function generateSitemapIndex(){
$dir = $this->directory;
$files = scandir($dir);
unset($files[0],$files[1],$files[2]); // .. . generateindex.php
$xml = '<?xml version="1.0" encoding="UTF-8"?>';
$xml .= "\n";
$xml .= '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
$xml .= "\n";
foreach($files as $file){
$xml .= '<sitemap>';
$xml .= "\n";
$xml .= '<loc>http://'.$this->domain.'/sitemap/'.$file.'</loc>';
$xml .= "\n";
//$xml .= '<lastmod>2004-10-01T18:23:17+00:00</lastmod>';
$xml .= '</sitemap>';
$xml .= "\n";
}
$xml .= '</sitemapindex>';
$this->saveSitemap($xml,''.$this->directory.'/sitemapindex.xml');
}
function safeurl( $v ){
$v = strtolower( $v );
$v = preg_replace( "/[^a-z0-9]+/", "-", $v );
$v = trim( $v, "-" );
return $v;
}
}
?>