Moin,
basierend auf dem RSS Skript von Korni http://www.ip-symcon.de/forum/f53/rss-feeds-newsscript-6235/?highlight=rss habe ich mir das TV Programm der TV Spielfilm in eine html-Box erstellt.
Anleitung:
- Code in leeres Skript kopieren
- TV Logos in IPS Ordner webfront/user/icons/TV/ kopieren
- Auswählen ob Programm für 20:15, 22:00, jetzt oder Spielfilme (einfach entsprechende Zeile im Code einkommentieren
- max. Anzahl der Einträge anpassen
- Skript laufen lassen
- die automatisch erstellte „CONTENT“ Variable im WebFront verwenden
Gruß
Tobias
<?
/* Basis: RSS FEED Newsticker korny@korny.org
/* TV Programm: by Smokey
Script in einen Kategorie kopieren
Script gegebenenfalls umbenennen
Skrip ausführen, neue Variable "CONTENT" (wird automatisch angelegt) im WebFront benutzen
*/
//gewünschten Feed einkommentieren
//$url='http://www.tvmovie.de/rss/tvjetzt.xml'; // RSS FEED link eintragen
$url='http://www.tvmovie.de/rss/tv2015.xml'; // RSS FEED link eintragen
//$url='http://www.tvmovie.de/rss/tv2200.xml'; // RSS FEED link eintragen
//$url='http://www.tvmovie.de/rss/tvtipps-spielfilm.xml'; // RSS FEED link eintragen
$newsanzahl=7; // gewünschte Newsanzahl eingeben, keine aenderung = 5 News werden erstellt
// ab hier nicht mehr ändern
$group=0;
$id=$IPS_SELF;
$group=IPS_GetObject($id);
$group=$group['ParentID'];
$name=IPS_GetName($group);
// Hauptscript
$rss_channel = array();
$currently_writing = "";
$main = "";
$item_counter = 0;
function startElement($parser, $name, $attrs) {
global $rss_channel, $currently_writing, $main;
switch($name) {
case "RSS":
case "RDF:RDF":
case "ITEMS":
$currently_writing = "";
break;
case "CHANNEL":
$main = "CHANNEL";
break;
case "IMAGE":
$main = "IMAGE";
$rss_channel["IMAGE"] = array();
break;
case "ITEM":
$main = "ITEMS";
break;
default:
$currently_writing = $name;
break;
}
}
function endElement($parser, $name) {
global $rss_channel, $currently_writing, $item_counter;
$currently_writing = "";
if ($name == "ITEM") {
$item_counter++;
}
}
function characterData($parser, $data) {
global $rss_channel, $currently_writing, $main, $item_counter;
if ($currently_writing != "") {
switch($main) {
case "ITEMS":
if (isset($rss_channel[$main][$item_counter][$currently_writing])) {
$rss_channel[$main][$item_counter][$currently_writing] .= $data;
} else {
//print ("rss_channel[$main][$item_counter][$currently_writing] = $data<br>");
$rss_channel[$main][$item_counter][$currently_writing] = $data;
}
break;
}
}
}
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
$data=curl_string($url);
xml_parse($xml_parser,$data);
xml_parser_free($xml_parser);
// putting in array
$news=array();
if (isset($rss_channel["ITEMS"]))
{
if (count($rss_channel["ITEMS"]) > 0)
for($i = 0;$i < count($rss_channel["ITEMS"]);$i++) $news[]=$rss_channel["ITEMS"][$i];
}
$nr_news = "";
$c=0;
foreach($news as $key=>$val)
{
if($c<$nr_news)
{
# echo "<p align=left>";
# echo '<a href="'.$val['LINK'].'">'.$val['TITLE'].'</a> - '.$val['PUBDATE'].'<br>'.''.$val['DESCRIPTION'].'</font></p>';
}
$c++;
}
function curl_string ($url,$user_agent='Mozilla 4.0'){
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_TIMEOUT, 120);
$result = curl_exec ($ch);
curl_close($ch);
return $result;
}
$news="";
for($i=0;$i<count($rss_channel['ITEMS']);$i++) {
$j="0";
$news[$i][$j]=$rss_channel['ITEMS'][$i]['TITLE']."";
$j++;
$news[$i][$j]=$rss_channel['ITEMS'][$i]['LINK']."";
$j++;
$news[$i][$j]=$rss_channel['ITEMS'][$i]['DESCRIPTION']."";
$j++;
$news[$i][$j]=""; //$rss_channel['ITEMS'][$i]['PUBDATE']."" ==> PUDATE gibt es bei TV Programm nicht
$j++;
$news[$i][$j]=$rss_channel['ITEMS'][$i]['GUID']."";
}
$result="";
$result = "<table width='90%' align='center'>
";
$result .= "<tr><td><b>Sender</b></td><td><b>Zeit</b></td><td><b>Sendung</b></td><td><b>Detail</b></td></tr>
";
for($i=0;$i<$newsanzahl;$i++) {
$result .= "<tr>
";
//Sender
$temp ="";
$newsline=$news[$i][0];
$newsline=text_formatierung($newsline);
$temp = substr($newsline,6,strpos($newsline," - ",6));
$temp = substr($temp,0,strpos($temp," - "));
switch($temp) {
case "ARD":
$result .= "<td><img src=/user/icons/TV/ard_30x30.png></td>
";
break;
case "ZDF":
$result .= "<td><img src=/user/icons/TV/zdf_30x30.png></td>
";
break;
case "RTL":
$result .= "<td><img src=/user/icons/TV/rtl_30x30.png></td>
";
break;
case "SAT.1":
$result .= "<td><img src=/user/icons/TV/sat1_30x30.png></td>
";
break;
case "PRO 7":
$result .= "<td><img src=/user/icons/TV/pro7_30x30.png></td>
";
break;
case "RTL II":
$result .= "<td><img src=/user/icons/TV/rtl2_30x30.png></td>
";
break;
case "S RTL":
$result .= "<td><img src=/user/icons/TV/superrtl_30x30.png></td>
";
break;
default:
$result .= "<td></td>
";
break;
}
//Zeit
$newsline=$news[$i][0];
$newsline=text_formatierung($newsline);
$result .= "<td>".substr($newsline,0,5)."</td>
";
//Sendung
$newsline=$news[$i][0];
$newsline=text_formatierung($newsline);
$result .= "<td>".substr($newsline,strpos($newsline," - ")+3,strlen($newsline)-strpos($newsline," - "))."</td>
";
//Detail
$newsline=$news[$i][2];
$newsline=text_formatierung($newsline);
$result .= "<td>".$newsline."</td>
";
$result .= "</tr>
";
}
$result .= "</table>";
//Ergbenis in Variable schreiben
$vid = CreateVariableByName($group, "Content", 3);
//IPS_SetIcon($vid, "Distance");
IPS_SetVariableCustomProfile($vid, "~HTMLBox");
SetValue($vid, $result);
function text_formatierung($newsline){
// Hier können noch anpassungen gemacht werden
#$newsline=html_entity_decode($newsline);
#$newsline=str_replace(" ", " ", $newsline);
#$newsline=str_replace("ö", "ö", $newsline);
#$newsline=str_replace("Ãœ", "Ü", $newsline);
#$newsline=str_replace("ü", "ü", $newsline);
#$newsline=str_replace("ä", "ä", $newsline);
#$newsline=str_replace("ß", "ß", $newsline);
#$newsline=str_replace("–", "-", $newsline);
#$newsline=str_replace(''', "`", $newsline);
#$newsline=str_replace("&", "&", $newsline);
#$newsline=strip_tags($newsline);
$newsline=strip_tags($newsline);
$newsline=html_entity_decode($newsline);
$newsline=str_replace(" ", " ", $newsline);
$newsline=str_replace("ö", "ö", $newsline);
$newsline=str_replace("Ãœ", "Ü", $newsline);
$newsline=str_replace("ü", "ü", $newsline);
$newsline=str_replace("ä", "ä", $newsline);
$newsline=str_replace("ß", "ß", $newsline);
$newsline=str_replace("–", "-", $newsline);
$newsline=str_replace(''', "`", $newsline);
$newsline=str_replace("&", "&", $newsline);
$newsline=str_replace("Ö", "Ö", $newsline);
$newsline=str_replace("„", "\"", $newsline);
$newsline=str_replace("“", "\"", $newsline);
$newsline=str_replace("–", "-", $newsline);
$newsline=str_replace("„", "\"", $newsline);
$newsline=str_replace("“", "\"", $newsline);
$newsline=str_replace("„", "\"", $newsline);
$newsline=str_replace("–", "-", $newsline);
$newsline=preg_replace("/\r|
/s", "", $newsline);
return $newsline;
}
function CreateVariableByName($id, $name, $type)
{
global $IPS_SELF;
$vid = @IPS_GetVariableIDByName($name, $id);
if($vid === false)
{
$vid = IPS_CreateVariable($type);
IPS_SetParent($vid, $id);
IPS_SetName($vid, $name);
IPS_SetInfo($vid, "this variable was created by script #$IPS_SELF");
}
return $vid;
}
?>
TV.zip (29.6 KB)