function PurgeLogFiles($Directory, $Extension, $ID_OutSwitch, $ID_OutDays) { if (GetValue($ID_OutSwitch)) { IPSLogger_Dbg(c_LogId, 'Purging *.'.$Extension.' LogFiles in Directory '.$Directory); $Days = GetValue($ID_OutDays); $ReferenceDate=Date('Ymd', strtotime("-".$Days." days")); if ($Directory == "") { $Directory = IPS_GetKernelDir().'logs\\'; } if (($handle=opendir($Directory))===false) { IPSLogger_Err(c_LogId, 'Error Opening Directory '.$Directory); Exit; } while (($File = readdir($handle))!==false) { $FileDate = substr($File, strlen('IPSLogger_'), 8); $FileExtension = substr($File, strlen('IPSLogger_')+8+1, 3); if ($Extension==$FileExtension) { IPSLogger_Trc(c_LogId, 'Found File: '.$File.', FileDate='.$FileDate.', RefDate='.$ReferenceDate); if ($FileDate < $ReferenceDate) { IPSLogger_Inf(c_LogId, 'Delete LogFile: '.$Directory.$File); unlink($Directory.$File); } } } closedir($handle); } }
function Entertainment_NetPlayer_SendData($Data) { $Control = $Data[1]; $Command = $Data[2]; IPSLogger_Com(__file__, "Send Data to NetPlayer, Control='$Control', Command='$Command'"); if ($Command=='poweron') { NetPlayer_Power(true); } else if ($Command=='poweroff') { NetPlayer_Power(false); } else { IPSLogger_Err(__file__, "Received unknown Command '$Command' from Entertainment-->Check Configuration!"); } }
function Entertainment_SendData($DeviceName, $ControlType, $CommParams, $CommType) { $CommConfig = get_CommunicationConfiguration(); $CommInterface = $CommParams[0]; $FunctionName = $CommConfig[$CommInterface][c_Property_FunctionSnd]; $FunctionScript = $CommConfig[$CommInterface][c_Property_ScriptSnd]; $FunctionParameters = array(); foreach ($CommParams as $CommIdx=>$CommParam) { if ($CommParam==c_Template_Value) { $FunctionParameters[] = GetValue(get_ControlIdByDeviceName($DeviceName, $ControlType)); } else if ($CommParam==c_Template_Code) { $DeviceConfig = get_DeviceConfiguration(); $Value = GetValue(get_ControlIdByDeviceName($DeviceName, $ControlType)); $FunctionParameters[] = $DeviceConfig[$DeviceName][$ControlType][c_Property_Codes][$Value]; } else { $FunctionParameters[] = $CommParam; } } if (!Entertainment_Before_SendData($FunctionParameters)) { return; } IPSLogger_Trc(__file__, 'SendData '.$CommInterface.'.'.$FunctionName.'('.implode(',',$FunctionParameters).')'); try { include_once $FunctionScript; $Function = new ReflectionFunction($FunctionName); $Function->invoke($FunctionParameters); } catch (Exception $e) { IPSLogger_Err(__file__, 'Error Executing Function '.$FunctionName.':'.$e->getMessage()); } Entertainment_After_SendData($FunctionParameters); }
function get_ControlId($ControlName, $CircleId) { $VariableId = IPS_GetVariableIDByName($ControlName, $CircleId); if ($VariableId === false) { IPSLogger_Err(__file__, "Control '$ControlName' could NOT be found for CircleId=$CircleId"); exit; } return $VariableId; }
IPSWeatherFAT_SetValue('TomorrowTempMax', (string)$weather->high->attributes()->data); IPSWeatherFAT_SetValue('TomorrowIcon', str_replace(".gif", ".png", str_replace(IPSWEATHERFAT_ICONS_GOOGLE1, IPSWEATHERFAT_ICONS_SMALL, $weather->icon->attributes()->data))); } else if ($i==3) { IPSWeatherFAT_SetValue('Tomorrow1Day', str_replace($DaySourceArray, $DayDisplayArray, $weather->day_of_week->attributes()->data)); IPSWeatherFAT_SetValue('Tomorrow1ForecastShort', (string)$weather->condition->attributes()->data); IPSWeatherFAT_SetValue('Tomorrow1TempMin', (string)$weather->low->attributes()->data); IPSWeatherFAT_SetValue('Tomorrow1TempMax', (string)$weather->high->attributes()->data); IPSWeatherFAT_SetValue('Tomorrow1Icon', str_replace(".gif", ".png", str_replace(IPSWEATHERFAT_ICONS_GOOGLE1, IPSWEATHERFAT_ICONS_SMALL, $weather->icon->attributes()->data))); } else if ($i==4) { IPSWeatherFAT_SetValue('Tomorrow2Day', str_replace($DaySourceArray, $DayDisplayArray, $weather->day_of_week->attributes()->data)); IPSWeatherFAT_SetValue('Tomorrow2ForecastShort', (string)$weather->condition->attributes()->data); IPSWeatherFAT_SetValue('Tomorrow2TempMin', (string)$weather->low->attributes()->data); IPSWeatherFAT_SetValue('Tomorrow2TempMax', (string)$weather->high->attributes()->data); IPSWeatherFAT_SetValue('Tomorrow2Icon', str_replace(".gif", ".png", str_replace(IPSWEATHERFAT_ICONS_GOOGLE1, IPSWEATHERFAT_ICONS_SMALL, $weather->icon->attributes()->data))); } else { IPSLogger_Err(__file__, "Receive unknown Weather Forecast Condition"); } $i++; } // Wetter für Niederösterreich von ORF auslesen $lHTML=file_get_contents(IPSWEATHERFAT_ORF_URL); $forcast = ExtractData($lHTML, '<div class="fulltextWrapper" role="article">', '<div class="webcamLinks">', true, false); $forcastToday = '<h2>'.ExtractData($forcast, '<h2>', '</h2>').'</h2>'.ExtractData($forcast, '<p>', '</p>', false, false); $forcast = ExtractData($forcast, '</p>', '<div class="webcamLinks">', true, false); $forcastTomorrow = '<h2>'.ExtractData($forcast, '<h2>', '</h2>').'</h2>'.ExtractData($forcast, '<p>', '</p>', false, false); $forcast = ExtractData($forcast, '</p>', '<div class="webcamLinks">', true, false); $forcastTomorrow1 = '<h2>'.ExtractData($forcast, '<h2>', '</h2>').'</h2>'.ExtractData($forcast, '<p>', '</p>', false, false);
// CD Selection - List CDs in MP3 Repository } else if (substr($id,0,5)=="rc_cd") { NetPlayer_PlayDirectory($_GET['cd_path']); } else if ($id=="rc_mp_cdselectprev") { NetPlayer_NavigateCDBack(NP_COUNT_CDHTML); } else if ($id=="rc_mp_cdselectnext") { NetPlayer_NavigateCDForward(NP_COUNT_CDHTML); } else if (substr($id,0,6)=="rc_cat") { NetPlayer_SetCategory($_GET['cd_cat']); } else if ($id=="rc_mp_cdselectroot") { NetPlayer_SetCategory(''); } else if ($id=="rc_mp_cdselectback") { NetPlayer_SwitchToMP3Player(false); } else if (substr($id,0,11)=="rc_mp_track") { NetPlayer_SetPlayListPosition((int)$_GET['track']); // Mediaplayer Set Webradio Station } else if (substr($id,0,11)=="rc_mp_radio") { NetPlayer_PlayRadio($_GET['radiourl'], $_GET['radiotitel']); } else if ($id=="rc_mp_radioselectprev") { NetPlayer_NavigateRadioBack(NP_COUNT_RADIOHTML); } else if ($id=="rc_mp_radioselectnext") { NetPlayer_NavigateRadioForward(NP_COUNT_RADIOHTML); } else { IPSLogger_Err(__file__, "Received Unknown Netplayer ObjID=".$id); } ; /** @}*/ ?>
$ControlType = get_ControlType($IPS_VARIABLE); switch ($ControlType) { case c_Control_RoomPower: Entertainment_SetRoomPower($IPS_VARIABLE, $IPS_VALUE); break; case c_Control_DevicePower: Entertainment_SetDevicePower($IPS_VARIABLE, $IPS_VALUE); break; case c_Control_Source: Entertainment_SetSource($IPS_VARIABLE, $IPS_VALUE); break; case c_Control_Group: Entertainment_SetGroupControlVisibility($IPS_VARIABLE, $IPS_VALUE); break; case c_Control_Muting: case c_Control_Volume: case c_Control_Balance: case c_Control_Treble: case c_Control_Middle: case c_Control_Bass: case c_Control_Mode: case c_Control_Program: Entertainment_SetControl($IPS_VARIABLE, $IPS_VALUE); break; default: IPSLogger_Err(__file__, 'Unknown Control with ID='.$IPS_VARIABLE.' !'); } } /** @}*/ ?>
function Entertainment_SetDeviceControlByRoomControlId($RoomControlId, $Value) { $DeviceControlId = get_DeviceControlIdByRoomControlId($RoomControlId); if ($DeviceControlId !== false) { Entertainment_SetDeviceControl($DeviceControlId, $Value); } else { IPSLogger_Err(__file__, 'No DeviceControl found for RoomControlId='.$RoomControlId.', Name="'.IPS_GetName($RoomControlId).'"'); } }
* * Script wird für das WebFront um Änderungen an den Variablen vorzunehmen * */ include_once "IPSWatering.inc.php"; if ($_IPS['SENDER']=='WebFront') { $ControlId = $_IPS['VARIABLE']; $CircleId = get_CirclyIdByControlId($ControlId); $ControlType = get_ControlType($ControlId); switch($ControlType) { case c_Control_Active: IPSWatering_SetActive($ControlId, $_IPS['VALUE'], c_Mode_StartManual); break; case c_Control_StartTime: case c_Control_Duration: case c_Control_Program: case c_Control_Sensor: case c_Control_Automatic: IPSWatering_SetValue($ControlId, $_IPS['VALUE']); break; default: IPSLogger_Err(__file__, "Error Unknown ControlType $ControlType"); Exit; } } /** @}*/ ?>
function IPSLogger_PhpErrorHandler ($ErrType, $ErrMsg, $FileName, $LineNum, $Vars) { if (error_reporting() == 0) {return false;} // No Reporting of suppressed Erros (suppressed @) require_once "IPSLogger.inc.php"; $ErrorDetails = c_lf." Error in Script ".$FileName." on Line ".$LineNum; $FatalError = false; switch ($ErrType) { case E_ERROR: IPSLogger_Err("PHP", 'Error: '.$ErrMsg.$ErrorDetails); $FatalError = true; break; case E_WARNING: IPSLogger_Err("PHP", 'Warning: '.$ErrMsg.$ErrorDetails); break; case E_PARSE: IPSLogger_Err("PHP", 'Parsing Error: '.$ErrMsg.$ErrorDetails); $FatalError = true; break; case E_NOTICE: IPSLogger_Err("PHP", 'Notice: '.$ErrMsg.$ErrorDetails); break; case E_CORE_ERROR: IPSLogger_Err("PHP", 'Core Error: '.$ErrMsg.$ErrorDetails); $FatalError = true; break; case E_CORE_WARNING: IPSLogger_Err("PHP", 'Core Warning: '.$ErrMsg.$ErrorDetails); $FatalError = true; break; case E_COMPILE_ERROR: IPSLogger_Err("PHP", 'Compile Error: '.$ErrMsg.$ErrorDetails); $FatalError = true; break; case E_COMPILE_WARNING: IPSLogger_Err("PHP", 'Compile Warning: '.$ErrMsg.$ErrorDetails); $FatalError = true; break; case E_USER_ERROR: IPSLogger_Err("PHP", 'User Error: '.$ErrMsg.$ErrorDetails); $FatalError = true; break; case E_USER_WARNING: IPSLogger_Err("PHP", 'User Warning: '.$ErrMsg.$ErrorDetails); break; case E_USER_NOTICE: IPSLogger_Err("PHP", 'User Notice: '.$ErrMsg.$ErrorDetails); break; case E_STRICT: $FatalError = true; IPSLogger_Err("PHP", 'Runtime Notice: '.$ErrMsg.$ErrorDetails); break; default: IPSLogger_Err("PHP", 'Unknown Error: '.$ErrMsg.$ErrorDetails); $FatalError = true; break; } if (array_key_exists('ERROR_COUNT', $_IPS)) { $errorCount=$_IPS['ERROR_COUNT'] + 1; } else { $errorCount=1; } $_IPS['ERROR_COUNT'] = $errorCount; // Abort Processing during "Abort Flag" if (array_key_exists('ABORT_ON_ERROR', $_IPS) and $_IPS['ABORT_ON_ERROR']) { exit('Abort Processing during Error: '.$ErrMsg.$ErrorDetails); // Abort Processing during "FATAL Error" } elseif ($FatalError) { exit('Abort Processing during Fatal-Error: '.$ErrMsg.$ErrorDetails); // Abort Processing during maximal Error Counter } elseif ($errorCount > 10) { IPSLogger_Err("PHP", 'Maximal ErrorCount exceeded for this Session --> Abort Processing'); exit('Abort Processing during exceed of maximal ErrorCount: '.$ErrMsg.$ErrorDetails); } else { return false; } }
function CopyGraphics($variableId_Display) { if (GetValue($variableId_Display)) { $SourceYear = IPS_GetKernelDir().'media\\IPSTwilight_YearLimited.gif'; $SourceDay = IPS_GetKernelDir().'media\\IPSTwilight_DayLimited.gif'; } else { $SourceYear = IPS_GetKernelDir().'media\\IPSTwilight_YearUnlimited.gif'; $SourceDay = IPS_GetKernelDir().'media\\IPSTwilight_DayUnlimited.gif'; } if (!copy($SourceYear, IPS_GetKernelDir().'media\\IPSTwilight_Year.gif')) { IPSLogger_Err(__file__, "Error while coping $SourceYear to Destination File 'IPSTwilight_Year.gif'"); } if (!copy($SourceDay, IPS_GetKernelDir().'media\\IPSTwilight_Day.gif')) { IPSLogger_Err(__file__, "Error while coping $SourceDay to Destination File 'IPSTwilight_Day.gif'"); } }
function NetPlayer_SetSource($value) { if (GetValue(NP_ID_SOURCE)<>$value) { switch ($value) { case NP_IDX_SOURCECD: NetPlayer_SwitchToMP3Player(true, true); break; case NP_IDX_SOURCERADIO: NetPlayer_SwitchToRadio(); break; default: IPSLogger_Err(__file__, "Unknown SourceValue '$value'"); exit; } } }
CreateLink('Output Enabled', $ID_ProwlOutEnabled, $ID_Output, 10); CreateLink('Logging Level', $ID_ProwlOutLevel, $ID_Output, 20); CreateLink('Priority', $ID_ProwlOutPriority, $ID_Output, 30); } Register_PhpErrorHandler($moduleManager); // ---------------------------------------------------------------------------------------------------------------------------- // Some Tests // ---------------------------------------------------------------------------------------------------------------------------- IPSUtils_Include ("IPSLogger.inc.php", "IPSLibrary::app::core::IPSLogger"); // Some Test Messages IPSLogger_Fat(__file__, 'Test for a Fatal Error'); IPSLogger_Err(__file__, 'Test for a Error ...'); IPSLogger_Wrn(__file__, 'Test for a Warning'); IPSLogger_Not(__file__, 'Test for a Notification with Priority 0 (High)'); IPSLogger_Not(__file__, 'Test for a Notification with Priority 10 (Low)'); IPSLogger_Inf(__file__, 'Test for a Information Message ...'); IPSLogger_Dbg(__file__, 'Test for a Debug Message ...'); IPSLogger_Com(__file__, 'Test for a Communication Message ...'); IPSLogger_Trc(__file__, 'Test for a Trace Message ...'); IPSLogger_Tst(__file__, 'Test for a Test Message ...'); // ------------------------------------------------------------------------------------------------ function Register_PhpErrorHandler($moduleManager) { $file = IPS_GetKernelDir().'scripts\\__autoload.php'; if (!file_exists($file)) { throw new Exception($file.' could NOT be found!', E_USER_ERROR);
function get_ControlIdByDeviceName($DeviceName, $ControlType, $ErrorOnNotFound=true) { $ControlName = get_ControlNameByDeviceName($DeviceName, $ControlType, $ErrorOnNotFound); if ($ControlName !== false) { // Device has Control $Ids = IPS_GetChildrenIDs(c_ID_Devices); $DeviceId=false; foreach($Ids as $Idx => $Id) { if ($DeviceName == IPS_GetName($Id)) { $DeviceId = $Id; } } if ($DeviceId !== false) { // Found Device $Ids = IPS_GetChildrenIDs($DeviceId); foreach($Ids as $Idx => $Id) { if ($ControlName == IPS_GetName($Id)) { return $Id; } } } } if ($ErrorOnNotFound) { IPSLogger_Err(__file__, "ControlId could Not be found for Device='$DeviceName' and ControlType='$ControlType'"); exit; } return false; }
$WaterConfig = get_WateringConfiguration(); // Wert von Bewässerungs Sensor ermitteln $SensorLimit = GetValue(get_ControlId(c_Control_Sensor, $CircleId)); $SensorValue = false; if (array_key_exists(c_Property_Sensor, $WaterConfig[$CircleName])) { $SensorPath = $WaterConfig[$CircleName][c_Property_Sensor]; if ($SensorPath <> '') { $SensorId = IPSUtil_ObjectIDByPath($SensorPath); if ($SensorId===false) { IPSLogger_Wrn(__file__, "Specified Sensor '$SensorPath' could NOT be found"); } else { $SensorValue = GetValue($SensorId); } } } if ($SensorValue===false and $SensorLimit>0) { IPSLogger_Err(__file__, "Rainfall Sensor NOT defined for Circle '$CircleName'"); Exit; } // Bewässerung Starten if ($SensorLimit > 0 and $SensorValue!==false and $SensorLimit<=$SensorValue) { IPSWatering_LogNoActivationByRainfall($CircleId, $SensorLimit, $Rainfall); IPSWatering_CalcNextScheduleDateTime($CircleId); } else { IPSWatering_SetActive($ControlId, true, c_Mode_StartAutomatic); } ?>
if ($value==NP_IDX_RADIOPREV) { NetPlayer_NavigateRadioBack(NP_COUNT_RADIOVARIABLE); } else { NetPlayer_NavigateRadioForward(NP_COUNT_RADIOVARIABLE); } IPS_SLEEP(200); SetValue($variable, -1); break; case NP_ID_RADIOLIST: $radioName = NetPlayer_GetNameFromProfile($value,'NetPlayer_RadioList'); $radioList = NetPlayer_GetRadioList(); $radioUrl = $radioList[$radioName]; NetPlayer_PlayRadio($radioUrl, $radioName); break; default: IPSLogger_Err(__file__, 'Unknown ControlID '.$variable); } } elseif ($_IPS['SENDER'] == 'Execute') { } function NetPlayer_GetNameFromProfile($value, $name) { $profileData = IPS_GetVariableProfile($name); $associations = $profileData['Associations']; foreach ($associations as $idx=>$association) { if ($association['Value']==$value) { $name = $association['Name']; } } return $name; }
Entertainment_ReceiveData(array(c_Comm_NetPlayer, 'netplayer', 'poweron'), c_MessageType_Info); } else { Entertainment_ReceiveData(array(c_Comm_NetPlayer, 'netplayer', 'poweroff'), c_MessageType_Info); } break; case 'RemoteControl': $ControlId = get_ControlIdByDeviceName(c_Device_NetPlayer, c_Control_RemoteSourceType); if (GetValue(NP_ID_CONTROLTYPE) <> GetValue($ControlId)) { IPSLogger_Com(__file__, "Receive RemoteControlType ".GetValue(NP_ID_CONTROLTYPE)." for NetPlayer"); Entertainment_ReceiveData(array(c_Comm_NetPlayer, 'netplayertype', (string)GetValue(NP_ID_CONTROLTYPE)), c_MessageType_Info); } else { Entertainment_RefreshRemoteControlByDeviceName(c_Device_NetPlayer); } break; case 'MobileControl': //Entertainment_RefreshRemoteControlByDeviceName(c_Device_NetPlayer, c_Control_iRemoteSource); break; case 'ControlType': //IPSLogger_Com(__file__, "Receive RemoteControlType $IPS_VALUE for NetPlayer"); //Entertainment_ReceiveData(array(c_Comm_NetPlayer, 'netplayertype', (string)$IPS_VALUE), c_MessageType_Info); break; default: IPSLogger_Err(__file__, "Unknown Variable $variableName"); Exit; } } IPS_SemaphoreLeave('NetPlayer'); /** @}*/ ?>