Moin,
hier endlich das versprochene Script, welches bei meinem Abfallunternehmen die Termine per ics-File abholt und in meine Variablen packt. Ist bestimmt nicht schön, funktioniert aber:
<?php
class ics {
/* Function is to get all the contents from ics and explode all the datas according to the events and its sections */
function getIcsEventsAsArray($file) {
$icalString = file_get_contents ( $file );
If (!$icalString) {exit("Abfalltermine konnten nicht heruntergeladen werden!");}
$icsDates = array ();
/* Explode the ICs Data to get datas as array according to string ‘BEGIN:’ */
$icsData = explode ( "BEGIN:", $icalString );
/* Iterating the icsData value to make all the start end dates as sub array */
foreach ( $icsData as $key => $value ) {
$icsDatesMeta [$key] = explode ( "\n", $value );
}
/* Itearting the Ics Meta Value */
foreach ( $icsDatesMeta as $key => $value ) {
foreach ( $value as $subKey => $subValue ) {
/* to get ics events in proper order */
$icsDates = $this->getICSDates ( $key, $subKey, $subValue, $icsDates );
}
}
return $icsDates;
}
/* funcion is to avaid the elements wich is not having the proper start, end and summary informations */
function getICSDates($key, $subKey, $subValue, $icsDates) {
if ($key != 0 && $subKey == 0) {
$icsDates [$key] ["BEGIN"] = $subValue;
} else {
$subValueArr = explode ( ":", $subValue, 2 );
if (isset ( $subValueArr [1] )) {
$icsDates [$key] [$subValueArr [0]] = $subValueArr [1];
}
}
return $icsDates;
}
}
//Helper function
function getLastLines($string, $n = 1) {
$lines = explode("\n", $string);
$lines = array_slice($lines, -$n);
return implode("\n", $lines);
}
$actualMonth = date("m");
If ($actualMonth == "12") {
$DataForThisYear = date("Y") + 1;
}
else { $DataForThisYear = date("Y");}
$ModuleId = 57981;
$DataForCity = "MeinOrt";
$DataForStreet = "MeineStrasse";
$Pappe = "";
$Hausmuell = "";
$Biomuell = "";
$Plastik = "";
$PappeID = @IPS_GetObjectIDByIdent("PaperTimes",$ModuleId);
$HausmuellID = @IPS_GetObjectIDByIdent("WasteTimes",$ModuleId);
$PlastikID = @IPS_GetObjectIDByIdent("YellowBagTimes",$ModuleId);
$BioID = @IPS_GetObjectIDByIdent("BioTimes",$ModuleId);
If ($actualMonth == "12") {
If ($PappeID) {$Pappe = (getLastLines(GetValueString($PappeID), 3))."\n";}
If ($HausmuellID) {$Hausmuell = (getLastLines(GetValueString($HausmuellID), 3))."\n";}
If ($BioID) {$Biomuell = (getLastLines(GetValueString($BioID), 3))."\n";}
If ($PlastikID) {$Plastik = (getLastLines(GetValueString($PlastikID), 3))."\n";}
}
$file = "https://www.awu-oberhavel.de/fuer-haushalte/zusatzinfos/tourenplan-".$DataForThisYear."/?no_cache=1&export=pap,hm,lvp,bio&city=".$DataForCity."&street=".$DataForStreet;
//Getting events from isc file
$obj = new ics();
$icsEvents = $obj->getIcsEventsAsArray( $file );
unset( $icsEvents [1] );
foreach( $icsEvents as $icsEvent){
// Getting start date and time
$start = isset( $icsEvent ['DTSTART;VALUE=DATE'] ) ? $icsEvent ['DTSTART;VALUE=DATE'] : $icsEvent ['DTSTART'];
$eventName = $icsEvent['SUMMARY'];
switch(substr($eventName, 0, 4)) {
case "Papp": $Pappe .= DateTime::createFromFormat('Ymd', $start)->format('d.m.Y')."\n"; break;
case "Haus": $Hausmuell .= DateTime::createFromFormat('Ymd', $start)->format('d.m.Y')."\n"; break;
case "Biom": $Biomuell .= DateTime::createFromFormat('Ymd', $start)->format('d.m.Y')."\n"; break;
case "Leic": $Plastik .= DateTime::createFromFormat('Ymd', $start)->format('d.m.Y')."\n"; break;
}
}
If ($PappeID) {SetValueString($PappeID, (trim($Pappe)));}
If ($HausmuellID) {SetValueString($HausmuellID, (trim($Hausmuell)));}
If ($BioID) {SetValueString($BioID, (trim($Biomuell)));}
If ($PlastikID) {SetValueString($PlastikID, (trim($Plastik)));}
?>
Viele Grüße
Peter
PS: Das Modul befindet sich jetzt auch im Symcon-Module-Store! 