Now using only a single array

This commit is contained in:
Michael 2020-01-05 13:13:36 +00:00
parent 45b747f13b
commit 4dec002dcb
1 changed files with 9 additions and 10 deletions

View File

@ -125,38 +125,37 @@ class UserItem
$notification_data = ['uid' => $uid, 'profiles' => []]; $notification_data = ['uid' => $uid, 'profiles' => []];
Hook::callAll('check_item_notification', $notification_data); Hook::callAll('check_item_notification', $notification_data);
$raw_profiles = $notification_data['profiles']; $profiles = $notification_data['profiles'];
$user = DBA::selectFirst('user', ['nickname'], ['uid' => $uid]); $user = DBA::selectFirst('user', ['nickname'], ['uid' => $uid]);
if (!DBA::isResult($user)) { if (!DBA::isResult($user)) {
return []; return [];
} }
$owner = DBA::selectFirst('contact', ['url'], ['self' => true, 'uid' => $uid]); $owner = DBA::selectFirst('contact', ['url', 'alias'], ['self' => true, 'uid' => $uid]);
if (!DBA::isResult($owner)) { if (!DBA::isResult($owner)) {
return []; return [];
} }
// This is our regular URL format // This is our regular URL format
$raw_profiles[] = $owner['url']; $profiles[] = $owner['url'];
// Now the alias
$profiles[] = $owner['alias'];
// Notifications from Diaspora are often with an URL in the Diaspora format // Notifications from Diaspora are often with an URL in the Diaspora format
$raw_profiles[] = DI::baseUrl() . '/u/' . $user['nickname']; $profiles[] = DI::baseUrl() . '/u/' . $user['nickname'];
$profiles = [];
// Validate and add profile links // Validate and add profile links
foreach ($raw_profiles AS $profile) { foreach ($profiles AS $key => $profile) {
// Check for invalid profile urls. 13 should be the shortest possible profile length: // Check for invalid profile urls. 13 should be the shortest possible profile length:
// http://a.bc/d // http://a.bc/d
// Additionally check for invalid urls that would return the normalised value "http:" // Additionally check for invalid urls that would return the normalised value "http:"
if ((strlen($profile) < 13) || (Strings::normaliseLink($profile) == 'http:')) { if ((strlen($profile) < 13) || (Strings::normaliseLink($profile) == 'http:')) {
unset($profiles[$key]);
continue; continue;
} }
// Add the profile
$profiles[] = $profile;
// Add the normalized form // Add the normalized form
$profile = Strings::normaliseLink($profile); $profile = Strings::normaliseLink($profile);
$profiles[] = $profile; $profiles[] = $profile;