﻿<?php
  header("Content-type: text/xml");
  
  echo(
    '<?xml version="1.0" encoding="UTF-8"?>'."\n".
      '<urlset'."\n".
        'xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"'."\n".
        'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'."\n".
        'xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">'."\n"
  );

  $links=array("updates", "join", "faq", "recovery", "contactus", "2257", "links");
  foreach($links as $link){
    echo('<url>'."\n");
      echo('<loc>https://'.$_SERVER['HTTP_HOST'].'/'.$link.'</loc>'."\n");
    echo('</url>'."\n");
  }
  
  $xml=simplexml_load_file("local/qsvideos.xml");
  
  foreach($xml->film as $film){
    if(!$film->hidden){
      $prefixes=[".jpg", "0.jpg", "1.jpg", "2.jpg", "3.jpg", "4.jpg", ".mp4"];
      for($i=0; $i<count($prefixes); $i++){
        $prefix=$prefixes[$i];
        echo('<url>'."\n");
          echo('<loc>https://cdn.'.$_SERVER['HTTP_HOST'].'/preview/'.$film->id.'/'.$film->id.'-prev'.$prefix.'</loc>'."\n");
          echo('<lastmod>'.str_replace('.', '-', $film->date).'</lastmod>'."\n");
        echo('</url>'."\n");
      }
    }
  }
  
  foreach($xml->film as $film){
    if(!$film->hidden){
      echo('<url>'."\n");
        echo('<loc>https://'.$_SERVER['HTTP_HOST'].'/previewmovie/'.$film->id.'</loc>'."\n");
        echo('<lastmod>'.str_replace('.', '-', $film->date).'</lastmod>'."\n");
      echo('</url>'."\n");
    }
  }
  
  echo('</urlset>'."\n");
?>