X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Fping.php;h=8e00ae31f177235a7e3be2be73747c881f9b3bab;hb=b1bc8ebbfa6d978a48c98c278d1b6081cbcd4ea8;hp=9593d6ed26df2c6e5964bf8de60ac2605c590eeb;hpb=f68929633b4eb04290381d269e80856fb65c4c5f;p=friendica.git diff --git a/mod/ping.php b/mod/ping.php index 9593d6ed26..8e00ae31f1 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -1,28 +1,43 @@ . + * */ use Friendica\App; use Friendica\Content\ForumManager; use Friendica\Content\Text\BBCode; -use Friendica\Core\Cache; -use Friendica\Core\Config; +use Friendica\Core\Cache\Duration; use Friendica\Core\Hook; -use Friendica\Core\L10n; -use Friendica\Core\PConfig; 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\Verb; +use Friendica\Protocol\Activity; use Friendica\Util\DateTimeFormat; use Friendica\Util\Temporal; -use Friendica\Util\Proxy as ProxyUtils; use Friendica\Util\XML; /** - * @brief Outputs the counts and the lists of various notifications + * Outputs the counts and the lists of various notifications * * The output format can be controlled via the GET parameter 'format'. It can be * - xml (deprecated legacy default) @@ -44,7 +59,7 @@ use Friendica\Util\XML; * "birthdays-today": 0, * "groups": [ ], * "forums": [ ], - * "notify": 0, + * "notification": 0, * "notifications": [ ], * "sysmsgs": { * "notice": [ ], @@ -120,12 +135,9 @@ function ping_init(App $a) $notifs = ping_get_notifications(local_user()); - $condition = ["`unseen` AND `uid` = ? AND `contact-id` != ?", local_user(), local_user()]; - $fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'contact-avatar', - 'network', 'created', 'object', 'parent-author-name', 'parent-author-link', 'parent-guid', 'wall']; - $params = ['order' => ['received' => true]]; - $items = Item::selectForUser(local_user(), $fields, $condition, $params); - + $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); if (DBA::isResult($items)) { $items_unseen = Item::inArray($items); $arr = ['items' => $items_unseen]; @@ -139,6 +151,7 @@ function ping_init(App $a) } } } + DBA::close($items); if ($network_count) { // Find out how unseen network posts are spread across groups @@ -164,15 +177,15 @@ function ping_init(App $a) $intros1 = q( "SELECT `intro`.`id`, `intro`.`datetime`, `fcontact`.`name`, `fcontact`.`url`, `fcontact`.`photo` - FROM `intro` LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id` - WHERE `intro`.`uid` = %d AND `intro`.`blocked` = 0 AND `intro`.`ignore` = 0 AND `intro`.`fid` != 0", + FROM `intro` INNER JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id` + WHERE `intro`.`uid` = %d AND NOT `intro`.`blocked` AND NOT `intro`.`ignore` AND `intro`.`fid` != 0", intval(local_user()) ); $intros2 = q( "SELECT `intro`.`id`, `intro`.`datetime`, `contact`.`name`, `contact`.`url`, `contact`.`photo` - FROM `intro` LEFT JOIN `contact` ON `intro`.`contact-id` = `contact`.`id` - WHERE `intro`.`uid` = %d AND `intro`.`blocked` = 0 AND `intro`.`ignore` = 0 AND `intro`.`contact-id` != 0", + 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", intval(local_user()) ); @@ -188,7 +201,7 @@ function ping_init(App $a) ); $mail_count = count($mails); - if (intval(Config::get('config', 'register_policy')) === \Friendica\Module\Register::APPROVE && is_site_admin()) { + if (intval(DI::config()->get('config', 'register_policy')) === \Friendica\Module\Register::APPROVE && is_site_admin()) { $regs = Friendica\Model\Register::getPending(); if (DBA::isResult($regs)) { @@ -197,7 +210,7 @@ function ping_init(App $a) } $cachekey = "ping_init:".local_user(); - $ev = Cache::get($cachekey); + $ev = DI::cache()->get($cachekey); if (is_null($ev)) { $ev = q( "SELECT type, start, adjust FROM `event` @@ -208,7 +221,7 @@ function ping_init(App $a) DBA::escape(DateTimeFormat::utcNow()) ); if (DBA::isResult($ev)) { - DI::cache()->set($cachekey, $ev, Cache::HOUR); + DI::cache()->set($cachekey, $ev, Duration::HOUR); } } @@ -269,23 +282,37 @@ function ping_init(App $a) 'photo' => $intro['photo'], 'date' => $intro['datetime'], 'seen' => false, - 'message' => L10n::t('{0} wants to be your friend'), + 'message' => DI::l10n()->t('{0} wants to be your friend'), ]; $notifs[] = $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'), + ]; + $notifs[] = $notif; + } + } else { $notif = [ 'id' => 0, - 'href' => DI::baseUrl() . '/admin/users/', - 'name' => $reg['name'], - 'url' => $reg['url'], - 'photo' => $reg['micro'], - 'date' => $reg['created'], + 'href' => DI::baseUrl() . '/admin/users/pending', + 'name' => $regs[0]['name'], + 'url' => $regs[0]['url'], + 'photo' => $regs[0]['micro'], + 'date' => $regs[0]['created'], 'seen' => false, - 'message' => L10n::t('{0} requested registration'), + 'message' => DI::l10n()->t('{0} and %d others requested registration', count($regs) - 1), ]; $notifs[] = $notif; } @@ -314,12 +341,8 @@ function ping_init(App $a) if (DBA::isResult($notifs)) { foreach ($notifs as $notif) { - $contact = Contact::getDetailsByURL($notif['url']); - if (isset($contact['micro'])) { - $notif['photo'] = ProxyUtils::proxifyUrl($contact['micro'], false, ProxyUtils::SIZE_MICRO); - } else { - $notif['photo'] = ProxyUtils::proxifyUrl($notif['photo'], false, ProxyUtils::SIZE_MICRO); - } + $contact = Contact::getByURL($notif['url'], false, ['micro', 'id', 'avatar']); + $notif['photo'] = Contact::getMicro($contact, $notif['photo']); $local_time = DateTimeFormat::local($notif['date']); @@ -354,7 +377,7 @@ function ping_init(App $a) if ($format == 'json') { $data['groups'] = $groups_unseen; $data['forums'] = $forums_unseen; - $data['notify'] = $sysnotify_count + $intro_count + $register_count; + $data['notification'] = $sysnotify_count + $intro_count + $register_count; $data['notifications'] = $notifications; $data['sysmsgs'] = [ 'notice' => $sysmsgs, @@ -383,7 +406,7 @@ function ping_init(App $a) } /** - * @brief Retrieves the notifications array for the given user ID + * Retrieves the notifications array for the given user ID * * @param int $uid User id * @return array Associative array of notifications @@ -406,8 +429,8 @@ function ping_get_notifications($uid) AND NOT (`notify`.`type` IN (%d, %d)) AND $seensql `notify`.`seen` ORDER BY `notify`.`date` $order LIMIT %d, 50", intval($uid), - intval(NOTIFY_INTRO), - intval(NOTIFY_MAIL), + intval(Type::INTRO), + intval(Type::MAIL), intval($offset) ); @@ -436,7 +459,7 @@ function ping_get_notifications($uid) $notification["message"] = $notification["msg_cache"]; } else { $notification["name"] = strip_tags(BBCode::convert($notification["name"])); - $notification["message"] = format_notification_message($notification["name"], strip_tags(BBCode::convert($notification["msg"]))); + $notification["message"] = Friendica\Model\Notify::formatMessage($notification["name"], strip_tags(BBCode::convert($notification["msg"]))); q( "UPDATE `notify` SET `name_cache` = '%s', `msg_cache` = '%s' WHERE `id` = %d", @@ -446,17 +469,17 @@ function ping_get_notifications($uid) ); } - $notification["href"] = DI::baseUrl() . "/notify/view/" . $notification["id"]; + $notification["href"] = DI::baseUrl() . "/notification/" . $notification["id"]; if ($notification["visible"] && !$notification["deleted"] - && empty($result[$notification["parent"]]) + && empty($result[$notification['parent']]) ) { // Should we condense the notifications or show them all? - if (PConfig::get(local_user(), 'system', 'detailed_notif')) { + if (DI::pConfig()->get(local_user(), 'system', 'detailed_notif')) { $result[$notification["id"]] = $notification; } else { - $result[$notification["parent"]] = $notification; + $result[$notification['parent']] = $notification; } } } @@ -466,7 +489,7 @@ function ping_get_notifications($uid) } /** - * @brief Backward-compatible XML formatting for ping.php output + * Backward-compatible XML formatting for ping.php output * @deprecated * * @param array $data The initial ping data array