diff options
author | Mario <mario@mariovavti.com> | 2023-02-23 09:51:37 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2023-02-23 09:51:37 +0000 |
commit | efcda1d37d609677b4fdc6a12c63feea250a3f5e (patch) | |
tree | 458fd20008007682e804c6141a8225a9cc7f8642 /Zotlabs/Lib | |
parent | 656400b4186a3d6529d47765d5101b7d2f982087 (diff) | |
download | volse-hubzilla-efcda1d37d609677b4fdc6a12c63feea250a3f5e.tar.gz volse-hubzilla-efcda1d37d609677b4fdc6a12c63feea250a3f5e.tar.bz2 volse-hubzilla-efcda1d37d609677b4fdc6a12c63feea250a3f5e.zip |
port some functions from streams
Diffstat (limited to 'Zotlabs/Lib')
-rw-r--r-- | Zotlabs/Lib/ActivityStreams.php | 59 |
1 files changed, 41 insertions, 18 deletions
diff --git a/Zotlabs/Lib/ActivityStreams.php b/Zotlabs/Lib/ActivityStreams.php index a07fdacb7..9049ffb5d 100644 --- a/Zotlabs/Lib/ActivityStreams.php +++ b/Zotlabs/Lib/ActivityStreams.php @@ -146,35 +146,58 @@ class ActivityStreams { } /** + * @brief get single property from Activity object + * + * @param string $property + * @param mixed $default return value if property or object not set + * or object is a string id which could not be fetched. + * @return mixed + */ + public function objprop(string $property, mixed $default = false): mixed { + $x = $this->get_property_obj($property,$this->obj); + return (isset($x)) ? $x : $default; + } + + /** * @brief Collects all recipients. * - * @param string $base + * @param mixed $base * @param string $namespace (optional) default empty * @return array */ - function collect_recips($base = '', $namespace = '') { - $x = []; + public function collect_recips(mixed $base = '', string $namespace = ''): array { + $result = []; + $tmp = []; $fields = ['to', 'cc', 'bto', 'bcc', 'audience']; - foreach ($fields as $f) { - $y = $this->get_compound_property($f, $base, $namespace); - if ($y) { - if (!is_array($this->raw_recips)) { - $this->raw_recips = []; - } - - if (!is_array($y)) { - $y = [$y]; - } - $this->raw_recips[$f] = $y; - $x = array_merge($x, $y); + foreach ($fields as $field) { + // don't expand these yet + $values = $this->get_property_obj($field, $base, $namespace); + if ($values) { + $values = force_array($values); + $tmp[$field] = $values; + $result = array_values(array_unique(array_merge($result, $values))); + } + // Merge the object recipients if they exist. + $values = $this->objprop($field); + if ($values) { + $values = force_array($values); + $tmp[$field] = (($tmp[$field]) ? array_merge($tmp[$field], $values) : $values); + $result = array_values(array_unique(array_merge($result, $values))); + } + // remove duplicates + if (is_array($tmp[$field])) { + $tmp[$field] = array_values(array_unique($tmp[$field])); } } -// not yet ready for prime time -// $x = $this->expand($x,$base,$namespace); - return $x; + $this->raw_recips = $tmp; + + // not yet ready for prime time + // $result = $this->expand($result,$base,$namespace); + return $result; } + function expand($arr, $base = '', $namespace = '') { $ret = []; |