diff --git a/src/Lib/Activity.php b/src/Lib/Activity.php index c4c1c03f2..717479d24 100644 --- a/src/Lib/Activity.php +++ b/src/Lib/Activity.php @@ -31,12 +31,12 @@ class Activity { public const ACTOR_CACHE_DAYS = 3; - // Turn $element into an array if it isn't already. + // Turn $element into a list array if it isn't already. $element could be string or complex AS object public static function force_array($element) { if (empty($element)) { return []; } - return (is_array($element)) ? $element : [$element]; + return (is_array($element) && array_is_list($element)) ? $element : [$element]; } // $x (string|array) @@ -480,11 +480,7 @@ class Activity $ret = []; if (array_key_exists('tag', $item) && is_array($item['tag'])) { - $ptr = $item['tag']; - if (!array_key_exists(0, $ptr)) { - $ptr = [$ptr]; - } - + $ptr = self::force_array($item['tag']); foreach ($ptr as $t) { if (!is_array($t)) { continue; @@ -690,11 +686,11 @@ class Activity $ret = []; if (isset($item['attachment']) && is_array($item['attachment']) && $item['attachment']) { - $ptr = $item['attachment']; - if (!array_key_exists(0, $ptr)) { - $ptr = [$ptr]; - } + $ptr = self::force_array($item['attachment']); foreach ($ptr as $att) { + if (! is_array($att)) { + continue; + } $entry = []; if ($att['type'] === 'Note') { if (array_key_exists('name', $att) && $att['name']) { @@ -2356,9 +2352,7 @@ class Activity $cover_photo = $ptr; } else { - if (! array_key_exists(0, $ptr)) { - $ptr = [$ptr]; - } + $ptr = self::force_array($ptr); foreach ($ptr as $p) { if (isset($p['type']) && $p['type'] === 'Link' && isset($p['href'])) { $cover_photo = $ptr['href']; diff --git a/src/Lib/ActivityStreams.php b/src/Lib/ActivityStreams.php index 97e73b6ae..daf27e46c 100644 --- a/src/Lib/ActivityStreams.php +++ b/src/Lib/ActivityStreams.php @@ -433,11 +433,11 @@ class ActivityStreams * @param string $property * @param mixed $base * @param string $namespace (optional) default empty - * @param bool $first (optional) default false, if true and result is a sequential array return only the first element + * @param bool $getFirst (optional) default false, if true and result is a sequential array return only the first element * @return NULL|mixed */ - public function get_compound_property(string $property, mixed $base = '', string $namespace = '', bool $first = false): mixed + public function get_compound_property(string $property, mixed $base = '', string $namespace = '', bool $getFirst = false): mixed { $x = $this->get_property_obj($property, $base, $namespace); if (self::is_url($x)) { @@ -447,7 +447,7 @@ class ActivityStreams } } - if ($first && is_array($x) && array_key_exists(0, $x)) { + if ($getFirst && is_array($x) && array_is_list($x)) { return $x[0]; } diff --git a/src/Lib/BaseObject.php b/src/Lib/BaseObject.php index 7f16f3c71..96bb552b0 100644 --- a/src/Lib/BaseObject.php +++ b/src/Lib/BaseObject.php @@ -40,7 +40,7 @@ class BaseObject return 'string'; } if (is_array($object[$element])) { - if (array_key_exists(0, $object[$element]) + if (array_is_list($object[$element]) || empty($object[$element])) { return 'array'; } else {