<?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');
|
}
|
|
?>
|