<?php
/*********************
* Steff / 24.05.2015 *
* nur zu Testzwecken *
* Feedback erwünscht *
*********************/

$itemid = $_GET["id"];

if ($itemid == "") {
	$itemid = 1150000;
}

$homepage = file_get_contents('http://m.shortnews.de/Detail/'.$itemid);

$newsbegin  = '<h2>';
$newsheadend = '</h2>';
$newstext = '<p>';
$newsend  = '</div>';

//Beginn und Ende des Newstextes suchen
$pos0 = strpos($homepage, $newsbegin);
$pos05 = strpos($homepage, $newsheadend);
$pos1 = strpos($homepage, $newstext);
$pos2 = strpos($homepage, $newsend, $pos1);

if ($pos0 !== false) {
	$newsheadline = substr($homepage, $pos0 + strlen($newsbegin), $pos05 - ($pos0 + strlen($newsbegin))); 
	$news = substr($homepage, $pos1 + strlen($newstext), $pos2-$pos1 - strlen($newstext));
	
	//HTML Code entfernen
	$remove = array('<p>', '</p>');
	$news = str_replace($remove, '', $news);
}
    
//Generate XML Response
header ("Content-Type:text/xml");  
$doc = new DOMDocument('1.0', 'UTF-8');
$root = $doc->createElement('NEWS');
$root = $doc->appendChild($root);

$time = time();
$data_validita = $doc->createElement('data_validita',date('Y-m-d',$time));
$root->appendChild($data_validita);

$ora_presunta_aggiornamento = $doc->createElement('ora_presunta_aggiornamento',date('H:i',$time+3600)); //Update in 1h
$ora_presunta_aggiornamento = $root->appendChild($ora_presunta_aggiornamento);

$res = $doc->createElement('RES');
$res->setAttribute('LASTHIT',"10"); //10?
$res->setAttribute('FIRSTHIT',"1"); //1?
$root->appendChild($res);

	$hit = $doc->createElement('HIT');
	$hit->setAttribute('NO',$itemid);
		$id = $doc->createElement('ID',$itemid);
		$hit->appendChild($id);
		$text = $doc->createElement('T',$newsheadline);
		$hit->appendChild($text);
		$hour = $doc->createElement('H','20:03');
		$hit->appendChild($hour);
		$description = $doc->createElement('D',$news);
		$hit->appendChild($description);
		$img = $doc->createElement('IMG','http://m.shortnews.de/DisplayImage/'.$itemid.'/150/150.jpg');
		//Bilder liegen teilweise im JPG-Format und teilweise im PNG-Format vor
		//Mit dem festen Link werden nur JPG angezeigt...
		$hit->appendChild($img);
		$quelle = $doc->createElement('P','http://m.shortnews.de/Detail/'.$itemid);
		$hit->appendChild($quelle);
	$res->appendChild($hit);

echo $doc->saveXML(); 

?>