allow filter_regexp to be an array

This commit is contained in:
Isaac Connor 2020-07-25 13:50:59 -04:00
parent 859428db51
commit a819b73e18
1 changed files with 23 additions and 5 deletions

View File

@ -42,7 +42,13 @@ class ZM_Object {
if ( $type == 'set' and is_array($args[0]) ) { if ( $type == 'set' and is_array($args[0]) ) {
$this->{$fn} = implode(',', $args[0]); $this->{$fn} = implode(',', $args[0]);
} else if ( array_key_exists($fn, $this->defaults) && is_array($this->defaults[$fn]) && isset($this->defaults[$fn]['filter_regexp']) ) { } else if ( array_key_exists($fn, $this->defaults) && is_array($this->defaults[$fn]) && isset($this->defaults[$fn]['filter_regexp']) ) {
$this->{$fn} = preg_replace($this->defaults[$fn]['filter_regexp'], '', $args[0]); if ( is_array($this->defaults[$fn]['filter_regexp']) ) {
foreach ( $this->defaults[$fn]['filter_regexp'] as $regexp ) {
$this->{$fn} = preg_replace($regexp, '', $args[0]);
}
} else {
$this->{$fn} = preg_replace($this->defaults[$fn]['filter_regexp'], '', $args[0]);
}
} else { } else {
$this->{$fn} = $args[0]; $this->{$fn} = $args[0];
} }
@ -168,9 +174,15 @@ class ZM_Object {
$this->{$k} = implode(',', $v); $this->{$k} = implode(',', $v);
} else if ( is_string($v) ) { } else if ( is_string($v) ) {
if ( array_key_exists($k, $this->defaults) && is_array($this->defaults[$k]) && isset($this->defaults[$k]['filter_regexp']) ) { if ( array_key_exists($k, $this->defaults) && is_array($this->defaults[$k]) && isset($this->defaults[$k]['filter_regexp']) ) {
$this->{$k} = preg_replace($this->defaults[$k]['filter_regexp'], '', trim($v)); if ( is_array($this->defaults[$k]['filter_regexp']) ) {
foreach ( $this->defaults[$k]['filter_regexp'] as $regexp ) {
$this->{$k} = preg_replace($regexp, '', $trim($v));
}
} else {
$this->{$k} = preg_replace($this->defaults[$k]['filter_regexp'], '', trim($v));
}
} else { } else {
$this->{$k} = trim($v); $this->{$k} = trim($v);
} }
} else if ( is_integer($v) ) { } else if ( is_integer($v) ) {
$this->{$k} = $v; $this->{$k} = $v;
@ -239,10 +251,16 @@ class ZM_Object {
} }
# Input might be a command separated string, or an array # Input might be a command separated string, or an array
} else { } else {
if ( array_key_exists($field, $this->defaults) && is_array($this->defaults[$field]) && isset($this->defaults[$field]['filter_regexp']) ) { if ( array_key_exists($field, $this->defaults) && is_array($this->defaults[$field]) && isset($this->defaults[$field]['filter_regexp']) ) {
$value = preg_replace($this->defaults[$field]['filter_regexp'], '', trim($value)); if ( is_array($this->defaults[$field]['filter_regexp']) ) {
foreach ( $this->defaults[$field]['filter_regexp'] as $regexp ) {
$this->{$field} = preg_replace($regexp, '', trim($value));
}
} else {
$value = preg_replace($this->defaults[$field]['filter_regexp'], '', trim($value));
}
} }
if ( $this->{$field} != $value ) { if ( $this->{$field} != $value ) {
$changes[$field] = $value; $changes[$field] = $value;