Merge branch 'dev' of codeberg.org:streams/streams into dev

This commit is contained in:
Mike Macgirvin 2024-06-04 16:49:32 -07:00
commit a1f432bbab
3 changed files with 12 additions and 18 deletions

View file

@ -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'];

View file

@ -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];
}

View file

@ -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 {