Skip to content

Commit

Permalink
Release v1.1.20240224
Browse files Browse the repository at this point in the history
  • Loading branch information
Wilkware committed Mar 19, 2024
1 parent aae9813 commit 9842c8d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
45 changes: 44 additions & 1 deletion libs/VariableHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,54 @@ protected function SetValueFloat(string $ident, float $value)
* @param string $ident Ident of the integer variable
* @param bool $value Enable or disable value the variable
*/
private function SetVariableDisabled(string $ident, bool $value)
protected function SetVariableDisabled(string $ident, bool $value)
{
$id = @$this->GetIDForIdent($ident);
if ($id !== false) {
IPS_SetDisabled($id, $value);
}
}

/**
* Check if the identifier is a valid variable identifier
*
* @param string $ident Variable identifier
* @param bool $exist may exist variable
* @return string (correct) variable identifier
*/
protected function GetVariableIdent(string $ident, bool $exist = false)
{
// Replace not allowed chars
$fixchar = ['/ä/', '/ö/', '/ü/', '/Ä/', '/Ö/', '/Ü/', '/ß/'];
$replace = ['ae', 'oe', 'ue', 'AE', 'OE', 'UE', 'ss'];
$ident = preg_replace($fixchar, $replace, $ident);

// Replace spaces with underscores
$ident = str_replace(' ', '_', $ident);

// If the passed identifier is empty, simply set it to underscore
if (empty($ident)) {
$ident = '_';
}

// Allow only allowed characters
$ident = preg_replace('/[^a-z0-9_]+/i', '', $ident);

// If the identifier starts with a number, prepend an underscore
//if (preg_match('/^[0-9]/', $ident)) {
// $ident = '_' . $ident;
//}

// If the identifier is already in use, append a number to make it unique
if ($exist) {
$counter = 1;
$originalIdent = $ident;
while (@$this->GetIDForIdent($ident) !== false) {
$ident = $originalIdent . '_' . $counter;
$counter++;
}
}

return $ident;
}
}
6 changes: 0 additions & 6 deletions libs/_traits.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,6 @@
define('IS_EBASE', 200); // Default errorcode
define('IS_NOTCREATED', IS_EBASE + 1); // Instance could not be created
}
if (!defined('vtBoolean')) {
define('vtBoolean', 0);
define('vtInteger', 1);
define('vtFloat', 2);
define('vtString', 3);
}

/**
* Include all helper trait classes.
Expand Down

0 comments on commit 9842c8d

Please sign in to comment.