File manager - Edit - /home/newsbmcs.com/public_html/play1/sitemap.php
Back
<?php if (session_status() == PHP_SESSION_NONE) { session_start(); } $username = isset( $_SESSION['username'] ) ? $_SESSION['username'] : ""; if(!defined('_AUTO_SITEMAP')){ 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(!defined('_AUTO_SITEMAP')){ if ( !USER_ADMIN ) { exit('access forbidden!'); } } if ( !PRETTY_URL ) { exit('Pretty url is disabled!'); } function containsAmpersand($string) { return strpos($string, '&') !== false; } $generated_sitemaps = []; $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') { $file_size_in_kb = filesize($directory.$file) / 1024; // Get file size in bytes and convert to KB if($file_size_in_kb >= 2){ $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 $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(dirname(__FILE__)."/sitemap-".$json_file_name.".xml", "w") or die("Unable to open file!"); $generated_sitemaps[] = "sitemap-".$json_file_name.".xml"; $content = $_str; fwrite($sitemap, $content); fclose($sitemap); //header('Location: sitemap.xml'); } $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) { $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(dirname(__FILE__).'/sitemap.xml', $sitemap_xml); $generated_sitemaps[] = '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(dirname(__FILE__).'/robots.txt', preg_replace('/^\s+|\s+$/m', '', $robots_txt)); } } 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(dirname(__FILE__)."/sitemap.xml", "w") or die("Unable to open file!"); $generated_sitemaps[] = "sitemap.xml"; $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(dirname(__FILE__).'/robots.txt', preg_replace('/^\s+|\s+$/m', '', $robots_txt)); } } if(!empty($generated_sitemaps) && !defined('_AUTO_SITEMAP')){ echo json_encode($generated_sitemaps); } ?>
| ver. 1.4 |
Github
|
.
| PHP 8.2.28 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings