Hi zusammen,
anbei ein kleiner Fix für PHP 7 (IPS v5.0).
<?
################################################################################
# Scriptbezeichnung: Online.Travel.ips.php
# Version: 1.2.20180316
# Author: Heiko Wilknitz (@Pitti)
# Original von sysrun (16.05.2010)
#
# Abfahrtstafeln von bahn.de
# ===========================
#
# Dieses Skript liest die An-und Abfahrtszeiten der Deutschen Bahn aus.
#
# Installation:
# -------------
#
# Dieses Skript richtet automatisch alle nötigen Objekte bei manueller
# Ausführung ein. Eine weitere manuelle Ausführung setzt alle benötigten Objekte
# wieder auf den Ausgangszustand.
#
# - Neues Skript erstellen
# - Diesen PHP-Code hineinkopieren
# - Abschnitt 'Konfiguration' den eigenen Gegebenheiten anpassen
# - Skript Abspeichern
# - Skript Ausführen
#
# ------------------------------ Konfiguration ---------------------------------
#
# Anzahl Zeilen in Fahrplantabelle (maximal 20 möglich)
$rows = 6;
#
# Schrittweite bzw. Offset der Startzeit konfigurierbar machen
# von Jetzt bis max. 12 Stunden in der Zukunft, sollte reichen
# Nur im Notfall anpassen ;-)
#
$min = 0; // Jetzt
$max = 720; // 12 Stunden
$step = 5; // kleine Schrittweite
$jump = 60; // große Schrittweite
$suffix = "min"; // min = Minuten
#
# Startzeit Offset Profil
#
$time = array(
array($min-3, "Jetzt", "", 0x0000FF),
array($min-2, "--", "", -1),
array($min-1, "-", "", -1),
array($min, "%d ".$suffix, "", 0x00FF00),
array($max+1, "+", "", -1),
array($max+2, "++", "", -1)
);
#
# Ankunft & Abfahrt Profil
#
$arrdep = array(
array(0, "Abfahrt", "", 0x00FF00),
array(1, "Ankunft", "", 0xFFFF00),
array(2, "Beides", "", 0x0000FF)
);
#
# Stationen Profil
# ACHTUNG: Hier die eigenen Stationen eintragen bzw. Ändern und Erweitern!!
# int => Stations ID
# string => Anzeigename
# hex => Farbcode
#
$stations = array(
array(8001825, "Erding", "", 0xFF8000),
array(8003879, "Markt Schwaben", "", 0xFF8000),
array(8004252, "Neubiberg", "", 0xFF8000)
);
#
# Suchen
#
$search = array(
array(0, '>', '', -1),
array(1, 'Suchen', '', 0x008000)
);
#
################################################################################
// INSTALLATION
if ($_IPS['SENDER']=='Execute') {
$pos = 0;
// Startzeit
$vpn = "Travel.Time";
$vid = CreateVariableByName($_IPS['SELF'], "Startzeit", 1);
CreateProfileInteger($vpn, 'Clock', '', '', $min, $max, 0, 0, $time);
IPS_SetVariableCustomProfile($vid, $vpn);
IPS_SetVariableCustomAction($vid, $_IPS['SELF']);
IPS_SetPosition($vid, $pos++);
SetValue($vid, $min-3);
// Wegzeit bzw. Laufweg
$vpn = "Travel.AwayTime";
$vid = CreateVariableByName($_IPS['SELF'], "Laufweg", 1);
CreateProfileInteger($vpn, 'Hourglass', '', ' min', 0, 60, 5, 0, NULL);
IPS_SetVariableCustomProfile($vid, $vpn);
IPS_SetVariableCustomAction($vid, $_IPS['SELF']);
IPS_SetPosition($vid, $pos++);
SetValue($vid, 0);
// Abfahrt und Ankunft
$vpn = "Travel.ArrivalsDeparture";
$vid = CreateVariableByName($_IPS['SELF'], "Abfahrt und Ankunft", 1);
CreateProfileInteger($vpn, 'Distance', '', '', 0, 0, 0, 0, $arrdep);
IPS_SetVariableCustomProfile($vid, $vpn);
IPS_SetVariableCustomAction($vid, $_IPS['SELF']);
IPS_SetPosition($vid, $pos++);
SetValue($vid, 0);
// Stationen
$vpn = "Travel.Stations";
$vid = CreateVariableByName($_IPS['SELF'], "Bahnhof/Haltestelle", 1);
CreateProfileInteger($vpn, 'Flag', '', '', 0, 0, 0, 0, $stations);
IPS_SetVariableCustomProfile($vid, $vpn);
IPS_SetVariableCustomAction($vid, $_IPS['SELF']);
IPS_SetPosition($vid, $pos++);
SetValue($vid, $stations[0][0]);
// Suchen
$vpn = "Travel.Search";
$vid = CreateVariableByName($_IPS['SELF'], "Reise", 1);
CreateProfileInteger($vpn, 'Script', '', '', 0, 0, 0, 0, $search);
IPS_SetVariableCustomProfile($vid, $vpn);
IPS_SetVariableCustomAction($vid, $_IPS['SELF']);
IPS_SetPosition($vid, $pos++);
SetValue($vid, 0);
// Fahrplan
$vid = CreateVariableByName($_IPS['SELF'], "Fahrplan ", 3);
IPS_SetVariableCustomProfile($vid, '~HTMLBox');
IPS_SetIcon($vid, "Database");
IPS_SetPosition($vid, $pos++);
}
// AKTION VIA WEBFRONT
else if($_IPS['SENDER'] == "WebFront") {
$name = IPS_GetName($_IPS['VARIABLE']);
switch ($name) {
case 'Startzeit':
switch($_IPS['VALUE']) {
case $min-3:
SetValue($_IPS['VARIABLE'], 0);
break;
case $min-2:
$_IPS['VALUE'] = GetValue($_IPS['VARIABLE']) - $jump;
if($_IPS['VALUE'] <= 0) {
$_IPS['VALUE'] = -3;
SetValue($_IPS['VARIABLE'], 0);
}
break;
case $min-1:
$_IPS['VALUE'] = GetValue($_IPS['VARIABLE']) - $step;
if($_IPS['VALUE'] <= 0) {
$_IPS['VALUE'] = -3;
SetValue($_IPS['VARIABLE'], 0);
}
break;
case $max+1:
$_IPS['VALUE'] = min($max, max(0, GetValue($_IPS['VARIABLE'])) + $step);
break;
case $max+2:
$_IPS['VALUE'] = min($max, max(0, GetValue($_IPS['VARIABLE'])) + $jump);
break;
default:
return;
break;
}
break;
case 'Reise':
// Daten holen
$vid = CreateVariableByName($_IPS['SELF'], "Startzeit", 1);
$start = GetValue($vid);
$vid = CreateVariableByName($_IPS['SELF'], "Laufweg", 1);
$time = GetValue($vid);
$vid = CreateVariableByName($_IPS['SELF'], "Abfahrt und Ankunft", 1);
$mode = GetValue($vid);
$vid = CreateVariableByName($_IPS['SELF'], "Bahnhof/Haltestelle", 1);
$station = GetValue($vid); //Formatted
// Fahrplan rendern
$vid = CreateVariableByName($_IPS['SELF'], "Fahrplan ", 3);
SetValue($vid, GenerateTimetable($start, $time, $mode, $station, $rows));
// Update Button zurückstellen
$_IPS['VALUE'] = 0;
break;
}
// Speichern
SetValue($_IPS['VARIABLE'], $_IPS['VALUE']);
}
# -------------------------------- FUNKTIONEN ----------------------------------
// Daten von bahne.de holen und rendern
function GenerateTimetable($start, $time, $mode, $station, $rows)
{
// Anzeige aufbereiten
$style = "";
$style = $style.'<style type="text/css">';
$style = $style.'table {border-collapse: collapse; font-size: 14px; width: 100%; }';
$style = $style.'td.fst {vertical-align: middle; text-align: center; width: 30px; padding: 5px; border-left: 1px solid rgba(255, 255, 255, 0.2); border-top: 1px solid rgba(255, 255, 255, 0.1); }';
$style = $style.'td.mid {vertical-align: middle; text-align: left; padding: 5px; border-top: 1px solid rgba(255, 255, 255, 0.1); }';
$style = $style.'td.lst {vertical-align: middle; text-align: left; width: 350px; padding: 5px; border-right: 1px solid rgba(255, 255, 255, 0.2); border-top: 1px solid rgba(255, 255, 255, 0.1); }';
$style = $style.'tr:last-child {border-bottom: 1px solid rgba(255, 255, 255, 0.2); }';
$style = $style.'tr:nth-child(even) { background-color: rgba(0, 0, 0, 0.2); }';
$style = $style.'.th { color: rgb(255, 255, 255); background-color: rgb(160, 160, 0); font-weight:bold; background-image: linear-gradient(top,rgba(0,0,0,0) 0,rgba(0,0,0,0.3) 50%,rgba(0,0,0,0.3) 100%); background-image: -o-linear-gradient(top,rgba(0,0,0,0) 0,rgba(0,0,0,0.3) 50%,rgba(0,0,0,0.3) 100%); background-image: -moz-linear-gradient(top,rgba(0,0,0,0) 0,rgba(0,0,0,0.3) 50%,rgba(0,0,0,0.3) 100%); background-image: -webkit-linear-gradient(top,rgba(0,0,0,0) 0,rgba(0,0,0,0.3) 50%,rgba(0,0,0,0.3) 100%); background-image: -ms-linear-gradient(top,rgba(0,0,0,0) 0,rgba(0,0,0,0.3) 50%,rgba(0,0,0,0.3) 100%); }';
$style = $style.'</style>';
// Startzeit berechnen
$dateTime = new DateTime();
if ($start > 0) {
$dateTime->modify('+'.$start.' minutes');
}
// Hier werden Verkehrsmittel ausgeschlossen
/*
$bahn->TypeBUS(false);
$bahn->TypeTRAM(false);
$bahn->TypeICE(false);
$bahn->TypeIC(false);
$bahn->TypeRE(false);
$bahn->TypeSBAHN(false);
$bahn->TypeUBAHN(false);
$bahn->TypeFAEHRE(false);
*/
// Abfahrt
$departure = '';
if ($mode == 0 || $mode == 2) {
// Parameter 1 ist der Bahnhof oder die Haltestelle
// (es muss kein Bahnhof sein, Bushaltestelle gehen auch)
// Parameter 2 ist die Art der Tafel: "Abfahrt" oder "Ankunft"
$bahn=new Bahn($station, "abfahrt");
// Hier werden Datum und Zeit gesetzt.
// Werden die nicht gesetzt wird die/das aktuelle Zeit/Datum genommen
$bahn->datum($dateTime->format('d.m.Y'));
$bahn->zeit($dateTime->format("H:i"));
// Jetzt das Ergebniss holen!
$status=$bahn->fetch();
if($status){
// Array mit den Informationen ausgeben:
$departure = RenderHTML($bahn, "Abfahrt", $time, $rows);
}
}
// Ankunft
$arrivals = '';
if ($mode == 1 || $mode == 2) {
// Parameter 1 ist der Bahnhof oder die Haltestelle
// (es muss kein Bahnhof sein, Bushaltestelle gehen auch)
// Parameter 2 ist die Art der Tafel: "Abfahrt" oder "Ankunft"
$bahn=new Bahn($station, "ankunft");
// Hier werden Datum und Zeit gesetzt.
// Werden die nicht gesetzt wird die/das aktuelle Zeit/Datum genommen
$bahn->datum($dateTime->format('d.m.Y'));
$bahn->zeit($dateTime->format("H:i"));
// Jetzt das Ergebniss holen!
$status=$bahn->fetch();
if($status){
// Array mit den Informationen ausgeben:
$arrivals = RenderHTML($bahn, "Ankunft", 0, $rows);
}
}
// HTML zusammenbauen
$html = $style;
$html = $html.$departure;
if (!empty($departure)) $html = $html.'<br />';
$html = $html.$arrivals;
// fertiges HTML zurueck
return $html;
}
// anzeige aufbereiten in eine html box
// $bahn - ergebnis der class.bahn.php
// $typ - "Ankunft" oder "Abfahrt"
// $wegezeit - eine wegezeit in minuten zum bahnhof. oder =0
// $zeilen - maximale Anzahl von Zeilen pro Tabelle
function RenderHTML($bahn, $typ, $wegezeit, $zeilen)
{
$str = '';
$str .= '<table>';
$str .= '<tr><td class="fst th" style="width:30px;"></td><td class="mid th" style="width:80px;">Zug</td><td class="mid th" style="width:50px;">'.$typ.'</td><td class="mid th" style="width:50px;">Diff.</td><td class="mid th" style="width:200px;">Richtung</td><td class="mid th" style="width:40px;">Gleis</td><td class="lst th">Aktuelles</td></tr>';
$pos = 0;
$journeys = count($bahn->timetable);
for($i=0; $i<$journeys; $i++) {
//$eintrag = explode(";", $bahn->timetable[$i]);
$caller = $bahn->timetable[$i]["type"];
$eintrag[0] = "<img src=/user/bahn/".strtolower($caller)."_24x24.gif>";
$colour="white"; // yellow or red, white ist der normalfall
$eintrag[1] = $bahn->timetable[$i]["train"];
$eintrag[2] = $bahn->timetable[$i]["time"];
// differenz zur aktuellen zeit ausrechnen.
$timestampField = strtotime($bahn->timetable[$i]["time"]);
$timestampNow = time();//+1*60*60;
$diff = $timestampField - $timestampNow;
//echo $diff." * ";
if ($diff >0) {
$eintrag[3] = $uhrzeit = date("H:i",$diff-1*60*60);
if ($diff > $wegezeit*60) {
$colour="white";
}
else {
$colour="yellow";
$eintrag[3]="<font color='#FFFF00'>".$eintrag[3];
}
}
else {
// nicht mehr zu schaffen da zeit abgelaufen
$eintrag[3] = "--:--";
if ($wegezeit <>0)
$eintrag[3]="<font color='#FF0000'>".$eintrag[3];
}
$eintrag[4] = $bahn->timetable[$i]["route_ziel"];
$eintrag[5] = isset($bahn->timetable[$i]["platform"]) ? $bahn->timetable[$i]["platform"] : '';
$eintrag[6] = $bahn->timetable[$i]["ris"];
$str .= "<tr>";
$count = count( $eintrag );
for ( $e = 0; $e < $count; $e++ ) {
if ( $e == 0 ) $class = 'fst';
else if ( $e == $count - 1 ) $class = 'lst';
else $class = 'mid';
$str .= '<td class="'.$class.'">'.$eintrag[$e].'</td>';
}
$str .= "</tr>";
$pos++;
if($pos >= $zeilen)
break;
}
$str .= "</table>";
return $str;
}
// Erzeugt eine Variable unterhalb {id} mit dem Namen {name} vom Typ [type}
// Existiert die Variable schon wird diese zurückgeliefert.
// Types: 0 = Boolean, 1 = Integer, 2 = Float, 3 = String
function CreateVariableByName($id, $name, $type)
{
$vid = @IPS_GetVariableIDByName($name, $id);
if($vid===false) {
$vid = IPS_CreateVariable($type);
IPS_SetParent($vid, $id);
IPS_SetName($vid, $name);
}
return $vid;
}
// Erzeugt ein Variablenprofil vom Typ {type} mit Name n{name}
function CreateProfile($name, $type)
{
if(!IPS_VariableProfileExists($name)) {
IPS_CreateVariableProfile($name, $type);
}
else {
$profile = IPS_GetVariableProfile($name);
if($profile['ProfileType'] != $type)
throw new Exception("Variable profile type does not match for profile ".$name);
}
}
// Erzeugt ein Integer-Variablenprofil
function CreateProfileInteger($name, $icon, $prefix, $suffix, $minvalue, $maxvalue, $step, $digits, $asso = NULL)
{
CreateProfile($name, 1);
IPS_SetVariableProfileIcon($name, $icon);
IPS_SetVariableProfileText($name, $prefix, $suffix);
IPS_SetVariableProfileDigits($name, $digits);
if(sizeof($asso) !== 0){
$minvalue = 0;
$maxvalue = 0;
}
IPS_SetVariableProfileValues($name, $minvalue, $maxvalue, $step);
if(sizeof($asso) !== 0){
foreach($asso as $ass) {
IPS_SetVariableProfileAssociation($name, $ass[0], $ass[1], $ass[2], $ass[3]);
}
}
}
# --------------------------------- KLASSE BAHN --------------------------------
#
# Author: Frederik Granna (sysrun)
# Version 0.1
#
# ------------------------------------------------------------------------------
class Bahn
{
var $_BASEURL="https://reiseauskunft.bahn.de/bin/bhftafel.exe/dn?maxJourneys=20";
var $_PARAMS=array();
var $timetable=array();
var $bahnhof=false;
var $_FETCHMETHOD;
function __construct($bahnhof=null,$type="abfahrt"){
$type=strtolower($type);
if(!$bahnhof)
$bahnhof="008003280";
$this->_init($bahnhof);
$this->fetchMethodCURL(true);
$this->boardType($type);
}
function TypeBUS($state=true){$this->_PARAMS['GUIREQProduct_5'] = ($state) ? "on" : false;}
function TypeICE($state=true){$this->_PARAMS['GUIREQProduct_0'] = ($state) ? "on" : false;}
function TypeIC($state=true){$this->_PARAMS['GUIREQProduct_1'] = ($state) ? "on" : false;}
function TypeRE ($state=true){$this->_PARAMS['GUIREQProduct_3'] = ($state) ? "on" : false;} // NV genannt
function TypeSBAHN ($state=true){$this->_PARAMS['GUIREQProduct_4'] = ($state) ? "on" : false;}
function TypeFAEHRE ($state=true){$this->_PARAMS['GUIREQProduct_6'] = ($state) ? "on" : false;} // UBAHN
function TypeTRAM ($state=true){$this->_PARAMS['GUIREQProduct_8'] = ($state) ? "on" : false;} // STrassenbahn
function TypeUBAHN ($state=true){$this->_PARAMS['GUIREQProduct_7'] = ($state) ? "on" : false;} // UBAHN
function boardType($type){
if($type=="ankunft")
$this->_PARAMS['boardType']="arr";
else
$this->_PARAMS['boardType']="dep";
}
function datum($datum){
$this->_PARAMS['date']=$datum;
}
function zeit($zeit){
$this->_PARAMS['time']=$zeit;
}
function fetch($html=null){
if($html){
return $this->_parse($html);
}else if($this->_FETCHMETHOD=="CURL"){
return $this->_queryCurl();
}
}
function _queryCurl(){
$this->buildQueryURL();
$result=$this->_call();
return $this->_parse($result);
}
function buildQueryURL(){
$fields_string="";
foreach($this->_PARAMS as $key=>$value){
if($value)
$fields_string .= $key.'='.urlencode($value).'&';
};
rtrim($fields_string,'&');
$this->_URL=$this->_BASEURL.$fields_string;
return $this->_URL;
}
function _parse($data){
$dom = new DOMDocument();
@$dom->loadHTML($data);
$select=$dom->getElementById("rplc0");
if($select->tagName=="select"){
$options=$select->getElementsByTagName("option");
foreach($options AS $op){
echo utf8_decode($op->getAttribute("value")."-".$op->nodeValue)."n";
}
return false;
}else{
$this->bahnhof=utf8_decode($select->getAttribute("value"));
$this->_process_dom($dom);
return true;
}
}
function _process_dom($dom){
$test=$dom->getElementById("sqResult")->getElementsByTagName("tr");
$data=array();
foreach($test as $k=>$t){
$tds=$t->getElementsByTagName("td");
foreach($tds AS $td){
$dtype=$td->getAttribute("class");
switch($dtype){
case 'train':
if($a=$td->getElementsByTagName("a")->item(0)){
$data[$k]['train']=str_replace(" ","",$a->nodeValue);
if($img=$a->getElementsByTagName("img")->item(0)){
if (preg_match('%/([a-z_]*)_24%', $img->getAttribute("src"), $regs)) {
switch($regs[1]){
case 'EC':
$data[$k]['type']="IC";
break;
default:
$data[$k]['type']=strtoupper($regs[1]);
break;
}
}
}
}
break;
case 'route':
if($span=@$td->getElementsByTagName("span")->item(0)){
$data[$k]['route_ziel']=$span->nodeValue;
}
preg_match_all('/(.*)s*([0-9:]{5})/', $td->nodeValue, $result, PREG_PATTERN_ORDER);
$tmp=array();
foreach($result[1] AS $rk=>$rv){
$tmp[$result[2][$rk]]=utf8_decode(trim(html_entity_decode(str_replace("n","",$rv))));
}
$data[$k]['route']=$tmp;
break;
case 'time':
case 'platform':
case 'ris':
$data[$k][$dtype]=$td->nodeValue;
break;
}
}
}
foreach($data AS $d){
if(array_key_exists("train",$d)){
foreach($d AS $dk=>$dv)
if(!is_array($dv))
$d[$dk]=ltrim(str_replace("
","",utf8_decode(trim(html_entity_decode($dv)))),"-");
$d['route_start']=$this->bahnhof;
$this->timetable[]=$d;
}
}
}
function fetchMethodCURL($state){
if($state){
$this->_FETCHMETHOD="CURL";
}else{
$this->_FETCHMETHOD="OTHER";
}
}
function _call(){
$this->_CH = curl_init();
curl_setopt($this->_CH,CURLOPT_RETURNTRANSFER,true);
curl_setopt($this->_CH,CURLOPT_URL,$this->_URL);
$result = curl_exec($this->_CH);
curl_close($this->_CH);
return $result;
}
function _init($bahnhof) {
$this->_PARAMS=array(
'country'=>'DEU',
'rt'=>1,
'GUIREQProduct_0'=>'on', // ICE
'GUIREQProduct_1'=>'on', // Intercity- und Eurocityzüge
'GUIREQProduct_2'=>'on', // Interregio- und Schnellzüge
'GUIREQProduct_3'=>'on', // Nahverkehr, sonstige Züge
'GUIREQProduct_4'=>'on', // S-Bahn
'GUIREQProduct_5'=>'on', // BUS
'GUIREQProduct_6'=>'on', // Schiffe
'GUIREQProduct_7'=>'on', // U-Bahn
'GUIREQProduct_8'=>'on', // Strassenbahn
'REQ0JourneyStopsSID'=>'',
'REQTrain_name'=>'',
'REQTrain_name_filterSelf'=>'1',
'advancedProductMode'=>'',
'boardType'=>'dep', // dep oder arr
'date'=>date("d.m.Y"),
'input'=>$bahnhof,
'start'=>'Suchen',
'time'=>date("H:i")
);
}
}
# ------------------------------------------------------------------------------
?>
Ciao Heiko