1
difenduandada
2024-10-15 7fd2948ee35c8e147ed35ce6d8502f94a98ddd22
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
<?php
session_start();
$username = isset( $_SESSION['username'] ) ? $_SESSION['username'] : "";
if ( !$username ) {
    exit('logout');
}
include_once 'config.php';
include_once 'init.php';
include_once 'includes/plugin.php';
 
if(file_exists(PLUGIN_PATH.'posts/Post.php')){
    include_once PLUGIN_PATH.'posts/Post.php';
}
if ( ADMIN_DEMO ) {
    exit('ADMIN DEMO');
}
if ( !USER_ADMIN ) {
    exit('access forbidden!');
}
if ( !PRETTY_URL ) {
    exit('Pretty url is disabled!');
}
function containsAmpersand($string) {
    return strpos($string, '&') !== false;
}
$str = '<?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">
<!-- generated by CloudArcade -->';
 
//domain
$str = $str.'
<url>
    <loc>'.DOMAIN.'</loc>
    <priority>1.00</priority>
</url>';
//check JSON language data
$json_file_names = array();
$directory = ABSPATH . 'locales/public/';
if(file_exists($directory)){
    $all_files = scandir($directory);
    foreach ($all_files as $file) {
        $file_info = pathinfo($file);
        if ($file_info['extension'] === 'json') {
            $json_file_names[] = $file_info['filename'];
        }
    }
}
if (!in_array('en', $json_file_names)) {
    if(get_setting_value('disable_en_language') && count($json_file_names) > 0){
        //
    } else {
        $json_file_names[] = 'en';
    }
}
//categories
$cats = get_all_categories();
//games
$onn = new PDO(DB_DSN, DB_USERNAME, DB_PASSWORD);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT slug, last_modified FROM games WHERE published = 1 ORDER BY id DESC LIMIT 10000";
$st = $conn->prepare($sql);
$st->execute();
$games = $st -> fetchAll();
$conn = null;
if(get_setting_value('lang_code_in_url')){
    foreach ($json_file_names as $json_file_name) {
        $lang_code = $json_file_name;
        $_str = $str;
        //categories
        foreach ($cats as $cat) {
            if (!containsAmpersand($cat->slug)) {
                $_str = $_str . '
                <url>
                    <loc>'.get_permalink('category', $cat->slug).'</loc>
                    <changefreq>weekly</changefreq>
                </url>';
            }
        }
        //blog
        if(defined('POST_ACTIVE')){
            $posts = Post::getList()['results'];
            if($posts){
                foreach ($posts as $post) {
                    if (!containsAmpersand($post->slug)) {
                        $_str = $_str . '
                        <url>
                            <loc>'.get_permalink('post', $post->slug).'</loc>
                        </url>';
                    }
                }
            }
        }
        //games
        foreach ($games as $game) {
            if (!containsAmpersand($game['slug'])) {
                $lastmod = $game['last_modified'];
                $_str .= '
                <url>
                    <loc>'.get_permalink('game', $game['slug']).'</loc>
                ';
                if ($lastmod) {
                    $_str .= '<lastmod>' . date('Y-m-d', strtotime($lastmod)) . '</lastmod>';
                }
                $_str .= '
                </url>
                ';
            }
        }
        $_str = $_str.'</urlset>';
        $sitemap = fopen("sitemap-".$json_file_name.".xml", "w") or die("Unable to open file!");
        $content = $_str;
        fwrite($sitemap, $content);
        fclose($sitemap);
        //header('Location: sitemap.xml');
    }
 
    $log_info = 'Sitemaps have been successfully generated:<br><br>';
 
    $sitemap_xml = '<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
 
    foreach ($json_file_names as $json_file_name) {
        $log_info .= 'sitemap-'.$json_file_name.'.xml<br>';
        $sitemap_xml .= '<sitemap>
            <loc>'.DOMAIN.'sitemap-'.$json_file_name.'.xml</loc>
            <lastmod>'.date("Y-m-d", filemtime('sitemap-'.$json_file_name.'.xml')).'</lastmod>
        </sitemap>';
    }
 
    $sitemap_xml .= '</sitemapindex>';
    file_put_contents('sitemap.xml', $sitemap_xml);
 
    if(!file_exists('robots.txt')){
        $domain = DOMAIN;
        if (substr($domain, -1) === '/') {
            $domain = substr($domain, 0, -1);
        }
        $robots_txt = 'User-agent: *
        Disallow: 
        Disallow: /includes/
        Disallow: /classes/
        Disallow: /admin/
        Disallow: /vendor/
        Sitemap: {{domain}}/sitemap.xml';
        $robots_txt = str_replace('{{domain}}', $domain, $robots_txt);
        file_put_contents('robots.txt', preg_replace('/^\s+|\s+$/m', '', $robots_txt));
    }
    echo $log_info;
} else {
    //categories
    foreach ($cats as $cat) {
        if (!containsAmpersand($cat->slug)) {
            $str = $str.'
            <url>
                <loc>'.get_permalink('category', $cat->slug).'</loc>
                <changefreq>weekly</changefreq>
            </url>';
        }
    }
    //blog
    if(defined('POST_ACTIVE')){
        $posts = Post::getList()['results'];
        if($posts){
            foreach ($posts as $post) {
                if (!containsAmpersand($post->slug)) {
                    $str = $str.'
                    <url>
                        <loc>'.get_permalink('post', $post->slug).'</loc>
                    </url>';
                }
            }
        }
    }
    //games
    foreach ($games as $game) {
        if (!containsAmpersand($game['slug'])) {
            $lastmod = $game['last_modified'];
            $str .= '
            <url>
                <loc>'.get_permalink('game', $game['slug']).'</loc>
            ';
            if ($lastmod) {
                $str .= '<lastmod>' . date('Y-m-d', strtotime($lastmod)) . '</lastmod>';
            }
            $str .= '
            </url>
            ';
        }
    }
 
    $str = $str.'</urlset>';
    $sitemap = fopen("sitemap.xml", "w") or die("Unable to open file!");
    $content = $str;
    fwrite($sitemap, $content);
    fclose($sitemap);
    if(!file_exists('robots.txt')){
        $domain = DOMAIN;
        if (substr($domain, -1) === '/') {
            $domain = substr($domain, 0, -1);
        }
        $robots_txt = 'User-agent: *
        Disallow: 
        Disallow: /includes/
        Disallow: /classes/
        Disallow: /admin/
        Disallow: /vendor/
        Sitemap: {{domain}}/sitemap.xml';
        $robots_txt = str_replace('{{domain}}', $domain, $robots_txt);
        file_put_contents('robots.txt', preg_replace('/^\s+|\s+$/m', '', $robots_txt));
    }
    header('Location: sitemap.xml');
}
 
?>