refactor icon parse

This commit is contained in:
Mike Macgirvin 2023-07-29 20:14:37 +10:00
parent 11ad15d42e
commit 8f358b23ba
2 changed files with 32 additions and 20 deletions

View file

@ -2304,24 +2304,8 @@ class Activity
$webfinger = $username . '@' . $h['host'];
}
if ($person_obj['icon']) {
if (is_array($person_obj['icon'])) {
if (array_key_exists('url', $person_obj['icon'])) {
$icon = $person_obj['icon']['url'];
} else {
if (is_string($person_obj['icon'][0])) {
$icon = $person_obj['icon'][0];
} elseif (array_key_exists('url', $person_obj['icon'][0])) {
$icon = $person_obj['icon'][0]['url'];
}
}
} else {
$icon = $person_obj['icon'];
}
}
if (!(isset($icon) && $icon)) {
$icon = z_root() . '/' . Channel::get_default_profile_photo();
}
$icon = self::getIcon($person_obj['icon']);
$cover_photo = false;
@ -2674,8 +2658,37 @@ class Activity
}
}
public static function getIcon($element)
{
$icon = null;
if (isset($element)) {
if (is_string($element)) {
$icon = $element;
}
if (is_array($element)) {
if (!array_key_exists(0, $element)) {
$element = [$element];
}
foreach ($element as $asobject) {
if (is_string($asobject)) {
$icon = $asobject;
break;
}
if (!empty($asobject['url']) && is_string($asobject['url'])) {
$icon = $asobject['url'];
break;
}
if (!empty($asobject['href']) && is_string($asobject['href'])) {
$icon = $asobject['href'];
break;
}
}
}
}
return $icon;
}
public static function drop($channel, $observer, $act)
public static function drop($channel, $observer, $act)
{
$r = q(
"select * from item where mid = '%s' and uid = %d limit 1",

View file

@ -48,7 +48,6 @@ class Dav extends Controller
$_SERVER['PHP_AUTH_USER'] = $name;
$_SERVER['PHP_AUTH_PW'] = $password;
}
break;
}
/* Signature authentication */