Path : /var/www/html/main/
File Upload :
Current File : /var/www/html/main/sitemap.php

<?php
/*!
 * Copyright Anucha Puangpaka
 * Contact anucha.ppk@icloud.com 062-479-9836
 */

error_reporting(E_ALL);
ini_set("display_errors", 1);
ini_set('memory_limit','-1');

$_GET['nu'] = (isset($_GET['nu']))?$_GET['nu']:'';
$_GET['sites'] = (isset($_GET['sites']))?$_GET['sites']:'';

include('config.php');

$lastmod = date('Y-m-d H:i:s');
$datetime = new DateTime($lastmod);
$result = $datetime->format('Y-m-d\TH:i:sP');

echo "<br>";

if($_GET['nu']==""){
  $xml = fopen('robots.txt', "wb");

  /*
  fwrite($xml, "User-agent: SemrushBot\n");
  fwrite($xml, "Disallow: /\n");*/

  fwrite($xml, "User-agent: *\n");
  fwrite($xml, "Disallow: ".str_replace("//", "/", "/$ap_folder/admin/")."\n");
  fwrite($xml, "Disallow: ".str_replace("//", "/", "/$ap_folder/api.php")."\n");

  /*
  fwrite($xml, "User-agent: Googlebot\n");
  fwrite($xml, "Allow: /\n");*/

  fwrite($xml, "\nUser-agent: *\n");
  fwrite($xml, "Allow: /\n");

  fwrite($xml, "\nSitemap: $ap_site$ap_folder"."sitemap.xml");
  fclose($xml);

  $xml = fopen('sitemap.xml', "wb");
  fwrite($xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
  fwrite($xml, "<sitemapindex xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n");
  fwrite($xml, "<sitemap>\n");
  fwrite($xml, "<loc>$ap_site$ap_folder"."sitemap/sitemap_index.xml</loc>\n");
  fwrite($xml, "<lastmod>$result</lastmod>\n");
  fwrite($xml, "</sitemap>\n");
  fwrite($xml, "<sitemap>\n");
  fwrite($xml, "<loc>$ap_site$ap_folder"."sitemap/sitemap_menus.xml</loc>\n");
  fwrite($xml, "<lastmod>$result</lastmod>\n");
  fwrite($xml, "</sitemap>\n");
  fwrite($xml, "<sitemap>\n");
  fwrite($xml, "<loc>$ap_site$ap_folder"."sitemap/sitemap_news.xml</loc>\n");
  fwrite($xml, "<lastmod>$result</lastmod>\n");
  fwrite($xml, "</sitemap>\n");
  fwrite($xml, "<sitemap>\n");
  fwrite($xml, "<loc>$ap_site$ap_folder"."sitemap/sitemap_pdf.xml</loc>\n");
  fwrite($xml, "<lastmod>$result</lastmod>\n");
  fwrite($xml, "</sitemap>\n");
  fwrite($xml, "<sitemap>\n");
  fwrite($xml, "<loc>$ap_site$ap_folder"."sitemap/sitemap_image.xml</loc>\n");
  fwrite($xml, "<lastmod>$result</lastmod>\n");
  fwrite($xml, "</sitemap>\n");
  fwrite($xml, "<sitemap>\n");
  fwrite($xml, "<loc>$ap_site$ap_folder"."sitemap/sitemap_video.xml</loc>\n");
  fwrite($xml, "<lastmod>$result</lastmod>\n");
  fwrite($xml, "</sitemap>\n");
  fwrite($xml, "</sitemapindex>");
  fclose($xml);

  echo "<p align='center'>";
  echo "<a href='$ap_site$ap_folder"."sitemap.xml' target='_blank'>Test Sitemap</a> | <a href='https://google.com/ping?sitemap=$ap_site$ap_folder/"."sitemap.xml' target='_blank'>Submitted URL to Google</a>";
  echo "</p>";
}

if($_GET['nu']=="index"){
  $xml = fopen('sitemap/sitemap_index.xml', "wb");
  fwrite($xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
  fwrite($xml, "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"
      xmlns:image=\"http://www.google.com/schemas/sitemap-image/1.1\"
      xmlns:video=\"http://www.google.com/schemas/sitemap-video/1.1\">\n");

  fwrite($xml, "<url>\n");
  fwrite($xml, "<loc>$ap_site$ap_folder</loc>\n");
  fwrite($xml, "<lastmod>$result</lastmod>\n");
  fwrite($xml, "<changefreq>daily</changefreq>\n");
  fwrite($xml, "<priority>1.00</priority>\n");
  fwrite($xml, "</url>\n");

  fwrite($xml, "<url>\n");
  fwrite($xml, "<loc>$ap_site$ap_folder"."ap/ebooks/</loc>\n");
  fwrite($xml, "<lastmod>$result</lastmod>\n");
  fwrite($xml, "<changefreq>daily</changefreq>\n");
  fwrite($xml, "<priority>1.00</priority>\n");
  fwrite($xml, "</url>\n");

  fwrite($xml, "<url>\n");
  fwrite($xml, "<loc>$ap_site$ap_folder"."ap/executiveline/</loc>\n");
  fwrite($xml, "<lastmod>$result</lastmod>\n");
  fwrite($xml, "<changefreq>daily</changefreq>\n");
  fwrite($xml, "<priority>1.00</priority>\n");
  fwrite($xml, "</url>\n");

  fwrite($xml, "<url>\n");
  fwrite($xml, "<loc>$ap_site$ap_folder"."ap/question-answer/question-answer.php</loc>\n");
  fwrite($xml, "<lastmod>$result</lastmod>\n");
  fwrite($xml, "<changefreq>daily</changefreq>\n");
  fwrite($xml, "<priority>1.00</priority>\n");
  fwrite($xml, "</url>\n");

  fwrite($xml, "<url>\n");
  fwrite($xml, "<loc>$ap_site$ap_folder"."ap/statistic/</loc>\n");
  fwrite($xml, "<lastmod>$result</lastmod>\n");
  fwrite($xml, "<changefreq>daily</changefreq>\n");
  fwrite($xml, "<priority>1.00</priority>\n");
  fwrite($xml, "</url>\n");

  $sql = "select * from ap_pages order by id desc";
  $query = mysqli_query($conn,$sql);
  while($rows = mysqli_fetch_array($query)){
    fwrite($xml, "<url>\n");
    fwrite($xml, escapeCode("<loc>$ap_site$ap_folder?page_id=$rows[id]&lang=$rows[lang]</loc>\n"));
    fwrite($xml, "<lastmod>$result</lastmod>\n");
    fwrite($xml, "<changefreq>daily</changefreq>\n");
    fwrite($xml, "<priority>0.80</priority>\n");
    if(!empty($rows['images'])){
      fwrite($xml, "<image:image>\n");
      fwrite($xml, escapeCode("<image:loc>$rows[images]</image:loc>\n"));
      fwrite($xml, escapeCode("<image:title>$rows[title]</image:title>\n"));
      fwrite($xml, escapeCode("<image:caption>$rows[title]</image:caption>\n"));
      fwrite($xml, "</image:image>");
    }
    fwrite($xml, "</url>\n");
  }

  $sql = "select * from ap_gallery order by id desc";
  $query = mysqli_query($conn,$sql);
  while($rows = mysqli_fetch_array($query)){
    fwrite($xml, "<url>\n");
    fwrite($xml, escapeCode("<loc>$ap_site$ap_folder?gal=$rows[code]&id=$rows[id]&lang=$rows[lang]</loc>\n"));
    fwrite($xml, "<lastmod>$result</lastmod>\n");
    fwrite($xml, "<changefreq>daily</changefreq>\n");
    fwrite($xml, "<priority>0.80</priority>\n");
    fwrite($xml, "</url>\n");
  }

  $sql = "select * from ap_gallery2 order by id desc";
  $query = mysqli_query($conn,$sql);
  while($rows = mysqli_fetch_array($query)){
    fwrite($xml, "<url>\n");
    fwrite($xml, escapeCode("<loc>$ap_site$ap_folder?gal2=$rows[code]&id=$rows[id]&lang=$rows[lang]</loc>\n"));
    fwrite($xml, "<lastmod>$result</lastmod>\n");
    fwrite($xml, "<changefreq>daily</changefreq>\n");
    fwrite($xml, "<priority>0.80</priority>\n");
    fwrite($xml, "</url>\n");
  }

  $sql = "select * from ap_gallery3 order by id desc";
  $query = mysqli_query($conn,$sql);
  while($rows = mysqli_fetch_array($query)){
    fwrite($xml, "<url>\n");
    fwrite($xml, escapeCode("<loc>$ap_site$ap_folder"."ap/ebooks/?nu=info&xcode=$rows[code]&xid=$rows[id]")."</loc>\n");
    fwrite($xml, "<lastmod>$result</lastmod>\n");
    fwrite($xml, "<changefreq>daily</changefreq>\n");
    fwrite($xml, "<priority>0.80</priority>\n");
    if(!empty($rows['images'])){
      fwrite($xml, "<image:image>\n");
      fwrite($xml, escapeCode("<image:loc>$rows[images]</image:loc>\n"));
      fwrite($xml, escapeCode("<image:title>$rows[title]</image:title>\n"));
      fwrite($xml, escapeCode("<image:caption>$rows[title]</image:caption>\n"));
      fwrite($xml, "</image:image>");
    }
    fwrite($xml, "</url>\n");
  }

  $sql = "select * from ap_externalurl where url_link like '%$_SERVER[SERVER_NAME]%' order by id desc";
  $query = mysqli_query($conn,$sql);
  while($rows = mysqli_fetch_array($query)){
    fwrite($xml, "<url>\n");
    fwrite($xml, escapeCode("<loc>$rows[url_link]</loc>\n"));
    fwrite($xml, "<lastmod>$result</lastmod>\n");
    fwrite($xml, "<changefreq>daily</changefreq>\n");
    fwrite($xml, "<priority>0.80</priority>\n");
    fwrite($xml, "</url>\n");
  }

  $sql = "select * from ap_edms order by id desc";
  $query = mysqli_query($conn,$sql);
  while($rows = mysqli_fetch_array($query)){
    fwrite($xml, "<url>\n");
    fwrite($xml, "<loc>".escapeCode("$ap_site$ap_folder"."contents/edms/$rows[files]")."</loc>\n");
    fwrite($xml, "<lastmod>$result</lastmod>\n");
    fwrite($xml, "<changefreq>daily</changefreq>\n");
    fwrite($xml, "<priority>0.80</priority>\n");
    fwrite($xml, "</url>\n");
  }

  fwrite($xml, "</urlset>");
  fclose($xml);

  echo "<p align='center'><a href='$ap_site$ap_folder"."sitemap/sitemap_index.xml' target='_blank'>Test Sitemap</a> | <a href='https://google.com/ping?sitemap=$ap_site$ap_folder"."sitemap/sitemap_index.xml' target='_blank'>Submitted URL to Google</a></p>";
}

if($_GET['nu']=="menus"){
  $xml = fopen('sitemap/sitemap_menus.xml', "wb");
  fwrite($xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
  fwrite($xml, "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"
      xmlns:news=\"http://www.google.com/schemas/sitemap-news/0.9\">\n");

  $sql = "select * from ap_menus";
  $query = mysqli_query($conn,$sql);
  while($rows = mysqli_fetch_array($query)){
    if($rows['url_link']!="#"){
      fwrite($xml, "<url>\n");
      if(substr($rows['url_link'],0,1)=="?" || substr($rows['url_link'],0,1)=="/" || substr($rows['url_link'],0,1)=="a" || substr($rows['url_link'],0,1)=="c"){
        fwrite($xml, escapeCode("<loc>$ap_site$ap_folder".$rows['url_link']."</loc>\n"));
      }else{
        fwrite($xml, escapeCode("<loc>$rows[url_link]</loc>\n"));
      }
      fwrite($xml, "<lastmod>$result</lastmod>\n");
      fwrite($xml, "<changefreq>daily</changefreq>\n");
      fwrite($xml, "<priority>0.80</priority>\n");
      fwrite($xml, "</url>\n");
    }
  }

  $sql = "select * from ap_menus2";
  $query = mysqli_query($conn,$sql);
  while($rows = mysqli_fetch_array($query)){
    if($rows['url_link']!="#"){
      fwrite($xml, "<url>\n");
      if(substr($rows['url_link'],0,1)=="?" || substr($rows['url_link'],0,1)=="/" || substr($rows['url_link'],0,1)=="a" || substr($rows['url_link'],0,1)=="c"){
        fwrite($xml, escapeCode("<loc>$ap_site$ap_folder".$rows['url_link']."</loc>\n"));
      }else{
        fwrite($xml, escapeCode("<loc>$rows[url_link]</loc>\n"));
      }
      fwrite($xml, "<lastmod>$result</lastmod>\n");
      fwrite($xml, "<changefreq>daily</changefreq>\n");
      fwrite($xml, "<priority>0.80</priority>\n");
      fwrite($xml, "</url>\n");
    }
  }

  $sql = "select * from ap_menus3";
  $query = mysqli_query($conn,$sql);
  while($rows = mysqli_fetch_array($query)){
    if($rows['url_link']!="#"){
      fwrite($xml, "<url>\n");
      if(substr($rows['url_link'],0,1)=="?" || substr($rows['url_link'],0,1)=="/" || substr($rows['url_link'],0,1)=="a" || substr($rows['url_link'],0,1)=="c"){
        fwrite($xml, escapeCode("<loc>$ap_site$ap_folder".$rows['url_link']."</loc>\n"));
      }else{
        fwrite($xml, escapeCode("<loc>$rows[url_link]</loc>\n"));
      }
      fwrite($xml, "<lastmod>$result</lastmod>\n");
      fwrite($xml, "<changefreq>daily</changefreq>\n");
      fwrite($xml, "<priority>0.80</priority>\n");
      fwrite($xml, "</url>\n");
    }
  }

  $sql = "select * from ap_menus4";
  $query = mysqli_query($conn,$sql);
  while($rows = mysqli_fetch_array($query)){
    if($rows['url_link']!="#"){
      fwrite($xml, "<url>\n");
      if(substr($rows['url_link'],0,1)=="?" || substr($rows['url_link'],0,1)=="/" || substr($rows['url_link'],0,1)=="a" || substr($rows['url_link'],0,1)=="c"){
        fwrite($xml, escapeCode("<loc>$ap_site$ap_folder".$rows['url_link']."</loc>\n"));
      }else{
        fwrite($xml, escapeCode("<loc>$rows[url_link]</loc>\n"));
      }
      fwrite($xml, "<lastmod>$result</lastmod>\n");
      fwrite($xml, "<changefreq>daily</changefreq>\n");
      fwrite($xml, "<priority>0.80</priority>\n");
      fwrite($xml, "</url>\n");
    }
  }

  fwrite($xml, "</urlset>");
  fclose($xml);

  echo "<p align='center'><a href='$ap_site$ap_folder"."sitemap/sitemap_menus.xml' target='_blank'>Test Sitemap</a> | <a href='https://google.com/ping?sitemap=$ap_site$ap_folder"."sitemap/sitemap_menus.xml' target='_blank'>Submitted URL to Google</a></p>";
}

if($_GET['nu']=="news"){
  $xml = fopen('sitemap/sitemap_news.xml', "wb");
  fwrite($xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
  fwrite($xml, "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"
      xmlns:news=\"http://www.google.com/schemas/sitemap-news/0.9\">\n");
  
  $sql = "select * from ap_pages order by id desc";
  $query = mysqli_query($conn,$sql);
  while($rows = mysqli_fetch_array($query)){
    fwrite($xml, "<url>\n");
    fwrite($xml, escapeCode("<loc>$ap_site$ap_folder?page_id=$rows[id]&lang=$rows[lang]</loc>\n"));
    fwrite($xml, "<news:news>\n");
    fwrite($xml, "<news:publication>\n");
    fwrite($xml, escapeCode("<news:name>$rows[title]</news:name>\n"));
    fwrite($xml, "<news:language>th</news:language>\n");
    fwrite($xml, "</news:publication>\n");
    fwrite($xml, "<news:publication_date>".date_reformat2($rows['date_time'])."</news:publication_date>\n");
    fwrite($xml, escapeCode("<news:title>$rows[title]</news:title>\n"));
    fwrite($xml, "</news:news>\n");
    fwrite($xml, "</url>\n");
  }

  fwrite($xml, "</urlset>");
  fclose($xml);

  echo "<p align='center'><a href='$ap_site$ap_folder"."sitemap/sitemap_news.xml' target='_blank'>Test Sitemap</a> | <a href='https://google.com/ping?sitemap=$ap_site$ap_folder"."sitemap/sitemap_news.xml' target='_blank'>Submitted URL to Google</a></p>";
}

if($_GET['nu']=="pdf"){
  $xml = fopen('sitemap/sitemap_pdf.xml', "wb");
  fwrite($xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
  fwrite($xml, "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n");

  $sql = "select * from ap_gallery3 order by id desc";
  $query = mysqli_query($conn,$sql);
  while($rows = mysqli_fetch_array($query)){
    fwrite($xml, "<url>\n");
    fwrite($xml, escapeCode("<loc>$rows[images2]</loc>\n"));
    fwrite($xml, "<lastmod>$result</lastmod>\n");
    fwrite($xml, "<changefreq>daily</changefreq>\n");
    fwrite($xml, "<priority>0.80</priority>\n");
    fwrite($xml, "</url>\n");
  }

  fwrite($xml, "</urlset>");
  fclose($xml);

  echo "<p align='center'><a href='$ap_site$ap_folder"."sitemap/sitemap_pdf.xml' target='_blank'>Test Sitemap</a> | <a href='https://google.com/ping?sitemap=$ap_site$ap_folder"."sitemap/sitemap_pdf.xml' target='_blank'>Submitted URL to Google</a></p>";
}

if($_GET['nu']=="image"){
  $xml = fopen('sitemap/sitemap_image.xml', "wb");
  fwrite($xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
  fwrite($xml, "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"
  xmlns:image=\"http://www.google.com/schemas/sitemap-image/1.1\">\n");

  $allowed_types = array('jpg', 'JPG','png', 'PNG');
  $sql = "select * from ap_gallery order by id desc";
  $query = mysqli_query($conn,$sql);
  while($rows = mysqli_fetch_array($query)){
    if($rows['createByStatus']=="Admin"){
      $dir = "contents/gallery/$rows[code]/";
    }else{
      $dir = "contents/$rows[createBy]/$rows[code]/";
    }
    $files = scandir($dir);
    $total = 0;
    $pic_path = array();
    foreach ($files as $key => $value) {
      if ($key > 0) {
        $file_parts = explode('.', $value);
        $ext = strtolower(array_pop($file_parts));
        if (in_array($ext, $allowed_types)) {
          $file_path[] = $dir.$value;
          $total++;
        }
      }
    }
    for ($i = 0; $i < $total; $i++) {
      $file['name'] = $file_path[$i];
      fwrite($xml, "<url>\n");
      fwrite($xml, "<loc>$ap_site$ap_folder?".escapeCode("gal=$rows[code]&id=$rows[id]&lang=$rows[lang]")."</loc>\n");
      fwrite($xml, "<lastmod>$result</lastmod>\n");
      fwrite($xml, "<changefreq>daily</changefreq>\n");
      fwrite($xml, "<priority>0.80</priority>\n");
      if(!empty($file['name'])){
        fwrite($xml, "<image:image>\n");
        fwrite($xml, "<image:loc>$ap_site$ap_folder".escapeCode($file['name'])."</image:loc>\n");
        fwrite($xml, escapeCode("<image:title>$rows[name]</image:title>\n"));
        fwrite($xml, escapeCode("<image:caption>$rows[name]</image:caption>\n"));
        fwrite($xml, "</image:image>");
      }
      fwrite($xml, "</url>\n");
    }
  }

  fwrite($xml, "</urlset>");
  fclose($xml);

  echo "<p align='center'><a href='$ap_site$ap_folder"."sitemap/sitemap_image.xml' target='_blank'>Test Sitemap</a> | <a href='https://google.com/ping?sitemap=$ap_site$ap_folder"."sitemap/sitemap_image.xml' target='_blank'>Submitted URL to Google</a></p>";
}

if($_GET['nu']=="video"){
  $xml = fopen('sitemap/sitemap_video.xml', "wb");
  fwrite($xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
  fwrite($xml, "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"
      xmlns:video=\"http://www.google.com/schemas/sitemap-video/1.1\">\n");
  
  $allowed_types = array('mp4', 'MP4');
  $sql = "select * from ap_gallery2 order by id desc";
  $query = mysqli_query($conn,$sql);
  while($rows = mysqli_fetch_array($query)){
    if($rows['createByStatus']=="Admin"){
      $dir = "contents/gallery2/$rows[code]/";
    }else{
      $dir = "contents/$rows[createBy]/$rows[code]/";
    }
    $files = scandir($dir);
    $total = 0;
    $pic_path = array();
    foreach ($files as $key => $value) {
      if ($key > 0) {
        $file_parts = explode('.', $value);
        $ext = strtolower(array_pop($file_parts));
        if (in_array($ext, $allowed_types)) {
          $file_path[] = $dir.$value;
          $total++;
        }
      }
    }
    for ($i = 0; $i < $total; $i++) {
      $file['name'] = $file_path[$i];
      fwrite($xml, "<url>\n");
      fwrite($xml, "<loc>$ap_site$ap_folder?".escapeCode("gal2=$rows[code]&id=$rows[id]&lang=$rows[lang]")."</loc>\n");
      fwrite($xml, "<video:video>\n");
      fwrite($xml, "<video:content_loc>$ap_site$ap_folder".escapeCode($file['name'])."</video:content_loc>\n");
      fwrite($xml, "<video:title>".basename($file['name'])."</video:title>\n");
      fwrite($xml, "</video:video>\n");
      fwrite($xml, "</url>\n");
    }
  }

  fwrite($xml, "</urlset>");
  fclose($xml);

  echo "<p align='center'><a href='$ap_site$ap_folder"."sitemap/sitemap_video.xml' target='_blank'>Test Sitemap</a> | <a href='https://google.com/ping?sitemap=$ap_site$ap_folder"."sitemap/sitemap_video.xml' target='_blank'>Submitted URL to Google</a></p>";
}

echo "<p align='center'>";
echo "<a href='sitemap.php'>Home</a>";
echo " | <a href='?nu=index'>Index</a>";
echo " | <a href='?nu=menus'>Menus</a>";
echo " | <a href='?nu=news'>News</a>";
echo " | <a href='?nu=pdf'>PDF</a>";
echo " | <a href='?nu=image'>Image</a>";
echo " | <a href='?nu=video'>Video</a>";
echo "</p>";

include('logs.php');

mysqli_close($conn);
?>