';
//domain
$str = $str.'
'.DOMAIN.'
1.00
';
//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 . '
'.get_permalink('category', $cat->slug).'
weekly
';
}
}
//blog
if(defined('POST_ACTIVE')){
$posts = Post::getList()['results'];
if($posts){
foreach ($posts as $post) {
if (!containsAmpersand($post->slug)) {
$_str = $_str . '
'.get_permalink('post', $post->slug).'
';
}
}
}
}
//games
foreach ($games as $game) {
if (!containsAmpersand($game['slug'])) {
$lastmod = $game['last_modified'];
$_str .= '
'.get_permalink('game', $game['slug']).'
';
if ($lastmod) {
$_str .= '' . date('Y-m-d', strtotime($lastmod)) . '';
}
$_str .= '
';
}
}
$_str = $_str.'';
$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:
';
$sitemap_xml = '
';
foreach ($json_file_names as $json_file_name) {
$log_info .= 'sitemap-'.$json_file_name.'.xml
';
$sitemap_xml .= '
'.DOMAIN.'sitemap-'.$json_file_name.'.xml
'.date("Y-m-d", filemtime('sitemap-'.$json_file_name.'.xml')).'
';
}
$sitemap_xml .= '';
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.'
'.get_permalink('category', $cat->slug).'
weekly
';
}
}
//blog
if(defined('POST_ACTIVE')){
$posts = Post::getList()['results'];
if($posts){
foreach ($posts as $post) {
if (!containsAmpersand($post->slug)) {
$str = $str.'
'.get_permalink('post', $post->slug).'
';
}
}
}
}
//games
foreach ($games as $game) {
if (!containsAmpersand($game['slug'])) {
$lastmod = $game['last_modified'];
$str .= '
'.get_permalink('game', $game['slug']).'
';
if ($lastmod) {
$str .= '' . date('Y-m-d', strtotime($lastmod)) . '';
}
$str .= '
';
}
}
$str = $str.'';
$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');
}
?>