-
Notifications
You must be signed in to change notification settings - Fork 21
/
sitemap.php
50 lines (48 loc) · 1.65 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
<?php header("Content-type: text/xml");
require("core/functions.php");
require("core/dbConnect.php");
$siteUrl = url();
$blockedPages = array("dbConnect.php", "cookie.php", "browser.php", "sitemap.php", "functions.php", "secure.php");
$getPosts = $connect->prepare("SELECT * FROM blog ORDER BY id DESC");
$getPosts->execute();
$files = glob("*.php");
$tools = glob("main/*.php");
$formattedTools = array();
foreach($tools as $tool){
array_push($formattedTools, basename($tool));
}
if($getPosts->rowCount() > 0){
$allPages = array_merge($files, $formattedTools);
$blogPosts = $getPosts->fetchAll(PDO::FETCH_ASSOC);
array_push($allPages, "blog/");
foreach($blogPosts as $post){
array_push($allPages, "blog/" . $post["sef"]);
}
}else{
$allPages = array_merge($files, $formattedTools);
}
$allPages = array_filter($allPages, function($el){
global $blockedPages;
return !in_array($el, $blockedPages);
});
echo('<?xml version="1.0" encoding="UTF-8"?>'); ?>
<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/0.9/sitemap.xsd">
<url>
<loc><?php echo($siteUrl); ?></loc>
<lastmod><?php echo(date(DATE_W3C, time())); ?></lastmod>
<priority>1.00</priority>
</url>
<?php
foreach($allPages as $filename){ ?>
<url>
<loc><?php echo($siteUrl . "/" . $filename); ?></loc>
<lastmod><?php echo(date(DATE_W3C, time())); ?></lastmod>
<priority>0.80</priority>
</url>
<?php }
echo("</urlset>");
$connect = null; ?>