-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsitemap.php
54 lines (51 loc) · 1.79 KB
/
sitemap.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
<?php
//
require("db.php");
//
$page = (int) (!isset($_GET["page"]) ? 1 : $_GET["page"]);
$page = ($page == 0 ? 1 : $page);
$xmlperpage=100;
$startpoint=($page * $xmlperpage) - $xmlperpage;
if(isset($_GET['page'])){
header('Content-type: text/xml');
echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
echo "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/09/sitemap.xsd\">\n";
$mresult = "SELECT sura,aya FROM quran_ayat limit $startpoint,$xmlperpage";
$db->query($mresult);
$db->setFetchMode(2);
$quran_table = $db->get();
foreach($quran_table as $mrow){
$links="".$base_url."/aya-".$mrow['aya']."-sora-".$mrow['sura'].".html";
print "<url>\n";
print "<loc>".XMLEntities($links)."</loc>\n";
print "</url>\n";
}
echo "</urlset>";
exit();
}
header("Content-type: text/xml");
echo '<?xml version="1.0" encoding="UTF-8"?>'."\n";
echo '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'."\n";
$mresult = "SELECT COUNT(*) as total FROM quran_ayat";
$db->query($mresult);
$db->setFetchMode(2);
$quran_table = $db->get('total');
$pagesnum =ceil($quran_table/ $xmlperpage);
##########################################
for ($i=1; $i<=$pagesnum; $i++) {
if ($i != $page) {
echo '<sitemap>'."\n";
echo '<loc>'.$base_url.'/sitemap-'.($i).'.xml</loc>'."\n";
echo '</sitemap>'."\n";
}else{
echo '<sitemap>'."\n";
echo '<loc>'.$base_url.'/sitemap-'.($i).'.xml</loc>'."\n";
echo '</sitemap>'."\n";
}
}
echo '</sitemapindex>'."\n";
//}
function XMLEntities($str) {
return str_replace('>','>',str_replace('<','<',str_replace('"','"',str_replace('\'',''',str_replace('&','&',iconv('utf-8','utf-8',$str))))));
}
?>