X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Fping.php;h=810598a0b3e5addda5d340df66fed33a86529a41;hb=215c6ecc14b799dc5359fd933275d9307ccd35ed;hp=5e6c478f7d6d390a04ccb615150ef096237b6d18;hpb=c92a333b174db8a5971b39ad93da4e075d4635eb;p=friendica.git diff --git a/mod/ping.php b/mod/ping.php index 5e6c478f7d..810598a0b3 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -28,8 +28,8 @@ use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Group; -use Friendica\Model\Item; use Friendica\Model\Notify\Type; +use Friendica\Model\Post; use Friendica\Model\Verb; use Friendica\Protocol\Activity; use Friendica\Util\DateTimeFormat; @@ -133,13 +133,13 @@ function ping_init(App $a) exit(); } - $notifs = ping_get_notifications(local_user()); + $notifications = ping_get_notifications(local_user()); $condition = ["`unseen` AND `uid` = ? AND NOT `origin` AND (`vid` != ? OR `vid` IS NULL)", local_user(), Verb::getID(Activity::FOLLOW)]; - $items = Item::selectForUser(local_user(), ['wall', 'uid', 'uri-id'], $condition); + $items = Post::selectForUser(local_user(), ['wall', 'uid', 'uri-id'], $condition); if (DBA::isResult($items)) { - $items_unseen = Item::inArray($items); + $items_unseen = Post::toArray($items); $arr = ['items' => $items_unseen]; Hook::callAll('network_ping', $arr); @@ -185,7 +185,7 @@ function ping_init(App $a) "SELECT `intro`.`id`, `intro`.`datetime`, `contact`.`name`, `contact`.`url`, `contact`.`photo` FROM `intro` INNER JOIN `contact` ON `intro`.`contact-id` = `contact`.`id` - WHERE `intro`.`uid` = %d AND NOT `intro`.`blocked` AND NOT `intro`.`ignore` AND `intro`.`contact-id` != 0 AND `intro`.`fid` = 0", + WHERE `intro`.`uid` = %d AND NOT `intro`.`blocked` AND NOT `intro`.`ignore` AND `intro`.`contact-id` != 0 AND (`intro`.`fid` = 0 OR `intro`.`fid` IS NULL)", intval(local_user()) ); @@ -263,8 +263,8 @@ function ping_init(App $a) $data['birthdays'] = $birthdays; $data['birthdays-today'] = $birthdays_today; - if (DBA::isResult($notifs)) { - foreach ($notifs as $notif) { + if (DBA::isResult($notifications)) { + foreach ($notifications as $notif) { if ($notif['seen'] == 0) { $sysnotify_count ++; } @@ -277,30 +277,44 @@ function ping_init(App $a) $notif = [ 'id' => 0, 'href' => DI::baseUrl() . '/notifications/intros/' . $intro['id'], - 'name' => $intro['name'], + 'name' => BBCode::convert($intro['name']), 'url' => $intro['url'], 'photo' => $intro['photo'], 'date' => $intro['datetime'], 'seen' => false, 'message' => DI::l10n()->t('{0} wants to be your friend'), ]; - $notifs[] = $notif; + $notifications[] = $notif; } } if (DBA::isResult($regs)) { - foreach ($regs as $reg) { + if (count($regs) <= 1 || DI::pConfig()->get(local_user(), 'system', 'detailed_notif')) { + foreach ($regs as $reg) { + $notif = [ + 'id' => 0, + 'href' => DI::baseUrl() . '/admin/users/pending', + 'name' => $reg['name'], + 'url' => $reg['url'], + 'photo' => $reg['micro'], + 'date' => $reg['created'], + 'seen' => false, + 'message' => DI::l10n()->t('{0} requested registration'), + ]; + $notifications[] = $notif; + } + } else { $notif = [ 'id' => 0, 'href' => DI::baseUrl() . '/admin/users/pending', - 'name' => $reg['name'], - 'url' => $reg['url'], - 'photo' => $reg['micro'], - 'date' => $reg['created'], + 'name' => $regs[0]['name'], + 'url' => $regs[0]['url'], + 'photo' => $regs[0]['micro'], + 'date' => $regs[0]['created'], 'seen' => false, - 'message' => DI::l10n()->t('{0} requested registration'), + 'message' => DI::l10n()->t('{0} and %d others requested registration', count($regs) - 1), ]; - $notifs[] = $notif; + $notifications[] = $notif; } } @@ -323,28 +337,17 @@ function ping_init(App $a) } return ($adate < $bdate) ? 1 : -1; }; - usort($notifs, $sort_function); - - if (DBA::isResult($notifs)) { - foreach ($notifs as $notif) { - $contact = Contact::getByURL($notif['url'], false, ['micro', 'id', 'avatar']); - $notif['photo'] = Contact::getMicro($contact, $notif['photo']); - - $local_time = DateTimeFormat::local($notif['date']); - - $notifications[] = [ - 'id' => $notif['id'], - 'href' => $notif['href'], - 'name' => $notif['name'], - 'url' => $notif['url'], - 'photo' => $notif['photo'], - 'date' => Temporal::getRelativeDate($notif['date']), - 'message' => $notif['message'], - 'seen' => $notif['seen'], - 'timestamp' => strtotime($local_time) - ]; + usort($notifications, $sort_function); + + array_walk($notifications, function (&$notification) { + if (empty($notification['photo'])) { + $contact = Contact::getByURL($notification['url'], false, ['micro', 'id', 'avatar']); + $notification['photo'] = Contact::getMicro($contact, $notification['photo']); } - } + + $notification['timestamp'] = DateTimeFormat::local($notification['date']); + $notification['date'] = Temporal::getRelativeDate($notification['date']); + }); } $sysmsgs = []; @@ -409,8 +412,8 @@ function ping_get_notifications($uid) do { $r = q( - "SELECT `notify`.*, `item`.`visible`, `item`.`deleted` - FROM `notify` LEFT JOIN `item` ON `item`.`id` = `notify`.`iid` + "SELECT `notify`.*, `post-view`.`visible`, `post-view`.`deleted` + FROM `notify` LEFT JOIN `post-view` ON `post-view`.`id` = `notify`.`iid` WHERE `notify`.`uid` = %d AND `notify`.`msg` != '' AND NOT (`notify`.`type` IN (%d, %d)) AND $seensql `notify`.`seen` ORDER BY `notify`.`date` $order LIMIT %d, 50",