diff --git a/src/etc/inc/plugins.inc b/src/etc/inc/plugins.inc index 190dcad7f..e92adb6c4 100644 --- a/src/etc/inc/plugins.inc +++ b/src/etc/inc/plugins.inc @@ -384,3 +384,37 @@ function plugins_xmlrpc_sync() } return $sync_settings; } + +function plugins_argument_map(&$arg) +{ + /* record the caller for a sensible log message */ + $caller = !empty(debug_backtrace()[1]['function']) ? debug_backtrace()[1]['function'] : 'unknown'; + + /* return value signals we have work to do */ + $ret = true; + $tmp = $arg; + + if (is_array($arg)) { + /* no need to deal with this now */ + } elseif (is_string($arg)) { + /* backwards compat with single string arguments */ + $tmp = explode(',', $arg); + $ret = !!strlen($arg); + } elseif (!is_null($arg)) { + log_msg(sprintf('%s: plugin argument map type "%s" not supported', $caller, gettype($arg)), LOG_WARNING); + $ret = false; + } + + if (is_array($tmp)) { + /* remove empty values or duplicates */ + $tmp = array_unique(array_filter($tmp)); + $ret = !!count($tmp); + } + + if ($ret) { + /* only modify argument if there is work to do */ + $arg = $tmp; + } + + return $ret; +}