<?php

error_reporting(0);   //neafisarea erorilor
date_default_timezone_set("Europe/Bucharest");  //ora, data romaniei
$nume_baza = "brgshkpu_xtpgos";   //numele bazei de date
$host_baza = "localhost";   //serverul bazei de date
$user_baza = "brgshkpu_vampiri";   //userul bazei de date
$parola_baza = "yjotogv99";   //parola bazei de date

$_SERVER["SERVER_NAME"] = str_replace("www.","",$_SERVER["SERVER_NAME"]);
$_SERVER["SERVER_NAME"] = "http://".$_SERVER["SERVER_NAME"];

$armany=@new mysqli($host_baza,$user_baza,$parola_baza,$nume_baza);
if(mysqli_connect_errno()) { echo 'Eroare baza de date!'; exit(); }

function getnume($title) {
$titlu = preg_replace("/\s[\s]+/"," ",$title);
$titlu = preg_replace("/[\s\W]+/"," ",$titlu);
$titlu = ucwords(strtolower($titlu));
$titlu = str_replace(" ", "-", $titlu);
return $titlu; }

header("Content-Type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>
<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n
<url>
<loc>".$_SERVER["SERVER_NAME"]."</loc>
<lastmod>".date("Y-m-d")."</lastmod>
<changefreq>always</changefreq>
<priority>1</priority>
</url>\n\n";

$categs = $armany->query("SELECT * FROM categorii ORDER BY id ASC");
while($categ=$categs->fetch_array()) {
if($categ["id"]=="1") { $categorie = "Manele"; }
else if($categ["id"]=="2") { $categorie = "House"; }
else if($categ["id"]=="3") { $categorie = "Straina"; }
else if($categ["id"]=="4") { $categorie = "Romaneasca"; }
else if($categ["id"]=="5") { $categorie = "HipHop"; }
else if($categ["id"]=="6") { $categorie = "Populara"; }else{ $categorie = "categorie".$categ["id"]; }
echo "<url>
<loc>".$_SERVER["SERVER_NAME"]."/".$categorie.".html</loc>
<lastmod>".date("Y-m-d")."</lastmod>
<changefreq>always</changefreq>
<priority>1</priority>
</url>\n"; }
echo "<url>
<loc>".$_SERVER["SERVER_NAME"]."/Videoclipuri.html</loc>
<lastmod>".date("Y-m-d")."</lastmod>
<changefreq>always</changefreq>
<priority>1</priority>
</url>\n\n

<url>
<loc>".$_SERVER["SERVER_NAME"]."/fast-and-furious-7-furios-si-iute-7-hd-online-subtitrat-2015.html</loc>
<lastmod>".date("Y-m-d")."</lastmod>
<changefreq>always</changefreq>
<priority>1</priority>
</url>\n\n";

$files = $armany->query("SELECT * FROM fisiere ORDER BY data DESC");
while($file=$files->fetch_array()) {
if(strlen($file["youtube"])>0) {
echo "<url>
<loc>".$_SERVER["SERVER_NAME"]."/videoclip/".getnume($file["nume"])."_".$file["id"].".html</loc>
<lastmod>".date("Y-m-d",$file["data"])."</lastmod>
<changefreq>always</changefreq>
<priority>1</priority>
</url>\n"; }
echo "<url>
<loc>".$_SERVER["SERVER_NAME"]."/descarca/".getnume($file["nume"])."_".$file["id"].".html</loc>
<lastmod>".date("Y-m-d",$file["data"])."</lastmod>
<changefreq>always</changefreq>
<priority>1</priority>
</url>\n"; }

echo "\n</urlset>";

?>
