diff options
-rw-r--r-- | Zotlabs/Lib/ActivityStreams.php | 59 | ||||
-rw-r--r-- | include/text.php | 8 |
2 files changed, 49 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 = []; diff --git a/include/text.php b/include/text.php index a09d1bd7b..d7ffa5550 100644 --- a/include/text.php +++ b/include/text.php @@ -3505,6 +3505,14 @@ function flatten_array_recursive($arr) { return($ret); } +// Turn $element into an array if it isn't already. +function force_array($element) { + if (empty($element)) { + return []; + } + return (is_array($element)) ? $element : [$element]; +} + /** * @brief Highlight Text. * |