<?php
include_once "simpleXmlUtils.php";

/* Settings */
$auto24dns = "https://auto.24tv.ua";
$tv24rss = "https://24tv.ua/resources/xml/origin/rssUkrnetAll.xml";
$auto24rss = "https://auto.24tv.ua/api/UrkNetRss";

/* Form requests for XML */
$opts = array(
  'http'=>array(
    'method' => "GET",
    'header' => "Accept: application/xhtml+xml,application/xml"
  )
);

$context = stream_context_create($opts);

$news24List = simplexml_load_string(file_get_contents($tv24rss));
$auto24List = simplexml_load_string(file_get_contents($auto24rss, false, $context));

/* Merge and sort two lists */
foreach ($auto24List->channel->item as $item) {
	$item->link = $auto24dns.$item->link;
	$item->enclosure->attributes()->url = $auto24dns.((string)$item->enclosure->attributes()->url);
	simplexml_import_simplexml($news24List->channel, $item);
}

/* Print XML */
header("Access-Control-Allow-Origin: *");
header('Content-type: application/xml');
echo $news24List->asXML();
?>