<?php
include($_SERVER["DOCUMENT_ROOT"].'/anunturi/config/loadconfig.php');

$sql = "SELECT * FROM `anunturi` WHERE `aprobat`='1' ORDER BY `data_publicarii` DESC LIMIT 15";
$query = $dbc->query($sql);

$queryp = $dbc->query("SELECT * FROM `pagina` WHERE `pid`='1' LIMIT 1");
$rwp = $queryp->fetch_assoc();

$sqld = "SELECT `data_publicarii` FROM `anunturi` ORDER BY `data_publicarii` DESC LIMIT 1";
$queryd = $dbc->query($sqld);
$rowd = $queryd->fetch_assoc();

date_default_timezone_set('Europe/Bucharest');

header( "Content-type: text/xml"); 
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
 <rss version='2.0' xmlns:atom='http://www.w3.org/2005/Atom'> 
     <channel>
       <title>".BASE_NAME." | RSS</title>
       <atom:link href=\"".BASE_URL."feed.xml\" rel=\"self\" type=\"application/rss+xml\"/>
       <link>".BASE_URL."</link>
       <description>".BASE_NAME." :: ".$rwp['titlu']." - ".$rwp['descriere']."</description>           
       <lastBuildDate>".date('D, d M Y H:i:s O', strtotime($rowd['data_publicarii']))."</lastBuildDate>    
      <language>ro-RO</language>
      <generator>https://www.adydev.ro/?v=1.0.0</generator>
      <copyright>Copyright (C) ".date('Y')." AdyDev.com. All Right Reserved</copyright>";
 
while($row = $query->fetch_array()){
   $title       = $row["titlu"];
   $link        = $row["seo"];
   $description = $row["descriere"];

$getcat = $dbc->query("SELECT * FROM `categorii` WHERE `cat_id`='{$row['cat_id']}' LIMIT 1");
$rwgc = $getcat->fetch_assoc();
   $categorie   = $rwgc["titlu"];

$getimage = $dbc->query("SELECT * FROM `imagini` WHERE `aid`='{$row['aid']}'");
   
$qusr = "SELECT * FROM `utilizatori` WHERE `uid`='{$row['uid']}' LIMIT 1";
$rusr = $dbc->query($qusr);
while($rowusr = $rusr->fetch_assoc()){
    $usruid       = $rowusr['uid'];
    $usremail     = $rowusr['email'];
    $usrprenume   = $rowusr['prenume'];
    $usrnume      = $rowusr['nume'];    
}

$getusermail = explode("@", $usremail);
$eusername = $getusermail[0];

echo " 
 <item>
   <title>$title</title>
   <link>".BASE_URL.$link.".html</link>
   <guid>".BASE_URL.$link.".html</guid>
   <pubDate>".date('D, d M Y H:i:s O', strtotime($row['data_publicarii']))."</pubDate>
   <description>$description</description>
   ";
 echo "<author>user".$usruid.'-'.$eusername."@".$rwset['domeniu']."(";
 if(!empty($usrprenume)){echo $usrprenume;}else{echo $eusername;}
 echo ")</author>
   <category>$categorie</category>
 </item>";
 }
 echo "\n</channel>\n</rss>";
?>