$notifications = DI::notification()->select([], ['order' => ['seen' => 'ASC', 'date' => 'DESC'], 'limit' => 50]);
if ($type == "xml") {
- $xmlnotes = [];
+ $xmlnotes = false;
if (!empty($notifications)) {
foreach ($notifications as $notification) {
$xmlnotes[] = ["@attributes" => $notification->toArray()];
}
}
- $notifications = $xmlnotes;
+ $result = $xmlnotes;
+ } elseif (count($notifications) > 0) {
+ $result = $notifications->getArrayCopy();
+ } else {
+ $result = false;
}
- return api_format_data("notes", $type, ['note' => $notifications->getArrayCopy()]);
+
+ return api_format_data("notes", $type, ['note' => $result]);
}
/**
use Friendica\Util\Proxy;
use Psr\Log\LoggerInterface;
+/**
+ * Factory for creating notification objects based on introductions
+ * Currently, there are two main types of introduction based notifications:
+ * - Friend suggestion
+ * - Friend/Follower request
+ */
class IntroductionFactory extends BaseFactory
{
/** @var Database */
use Friendica\Util\XML;
use Psr\Log\LoggerInterface;
+/**
+ * Factory for creating notification objects based on items
+ * Currently, there are the following types of item based notifications:
+ * - network
+ * - system
+ * - home
+ * - personal
+ */
class NotificationFactory extends BaseFactory
{
/** @var Database */
// Transform the different types of notification in an usable array
switch ($item['verb'] ?? '') {
case Activity::LIKE:
- return new \Friendica\Object\Notification\Notification(
- 'like',
- $this->baseUrl->get(true) . '/display/' . $item['parent-guid'],
- Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO),
- $item['author-link'],
- $this->l10n->t("%s liked %s's post", $item['author-name'], $item['parent-author-name']),
- $item['when'] ?? '',
- $item['ago'] ?? '',
- $item['seen'] ?? false);
+ return new \Friendica\Object\Notification\Notification([
+ 'label' => 'like',
+ 'link' => $this->baseUrl->get(true) . '/display/' . $item['parent-guid'],
+ 'image' => Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO),
+ 'url' => $item['author-link'],
+ 'text' => $this->l10n->t("%s liked %s's post", $item['author-name'], $item['parent-author-name']),
+ 'when' => $item['when'],
+ 'ago' => $item['ago'],
+ 'seen' => $item['seen']]);
case Activity::DISLIKE:
- return new \Friendica\Object\Notification\Notification(
- 'dislike',
- $this->baseUrl->get(true) . '/display/' . $item['parent-guid'],
- Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO),
- $item['author-link'],
- $this->l10n->t("%s disliked %s's post", $item['author-name'], $item['parent-author-name']),
- $item['when'] ?? '',
- $item['ago'] ?? '',
- $item['seen'] ?? false);
+ return new \Friendica\Object\Notification\Notification([
+ 'label' => 'dislike',
+ 'link' => $this->baseUrl->get(true) . '/display/' . $item['parent-guid'],
+ 'image' => Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO),
+ 'url' => $item['author-link'],
+ 'text' => $this->l10n->t("%s disliked %s's post", $item['author-name'], $item['parent-author-name']),
+ 'when' => $item['when'],
+ 'ago' => $item['ago'],
+ 'seen' => $item['seen']]);
case Activity::ATTEND:
- return new \Friendica\Object\Notification\Notification(
- 'attend',
- $this->baseUrl->get(true) . '/display/' . $item['parent-guid'],
- Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO),
- $item['author-link'],
- $this->l10n->t("%s is attending %s's event", $item['author-name'], $item['parent-author-name']),
- $item['when'] ?? '',
- $item['ago'] ?? '',
- $item['seen'] ?? false);
+ return new \Friendica\Object\Notification\Notification([
+ 'label' => 'attend',
+ 'link' => $this->baseUrl->get(true) . '/display/' . $item['parent-guid'],
+ 'image' => Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO),
+ 'url' => $item['author-link'],
+ 'text' => $this->l10n->t("%s is attending %s's event", $item['author-name'], $item['parent-author-name']),
+ 'when' => $item['when'],
+ 'ago' => $item['ago'],
+ 'seen' => $item['seen']]);
case Activity::ATTENDNO:
- return new \Friendica\Object\Notification\Notification(
- 'attendno',
- $this->baseUrl->get(true) . '/display/' . $item['parent-guid'],
- Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO),
- $item['author-link'],
- $this->l10n->t("%s is not attending %s's event", $item['author-name'], $item['parent-author-name']),
- $item['when'] ?? '',
- $item['ago'] ?? '',
- $item['seen'] ?? false);
+ return new \Friendica\Object\Notification\Notification([
+ 'label' => 'attendno',
+ 'link' => $this->baseUrl->get(true) . '/display/' . $item['parent-guid'],
+ 'image' => Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO),
+ 'url' => $item['author-link'],
+ 'text' => $this->l10n->t("%s is not attending %s's event", $item['author-name'], $item['parent-author-name']),
+ 'when' => $item['when'],
+ 'ago' => $item['ago'],
+ 'seen' => $item['seen']]);
case Activity::ATTENDMAYBE:
- return new \Friendica\Object\Notification\Notification(
- 'attendmaybe',
- $this->baseUrl->get(true) . '/display/' . $item['parent-guid'],
- Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO),
- $item['author-link'],
- $this->l10n->t("%s may attending %s's event", $item['author-name'], $item['parent-author-name']),
- $item['when'] ?? '',
- $item['ago'] ?? '',
- $item['seen'] ?? false);
+ return new \Friendica\Object\Notification\Notification([
+ 'label' => 'attendmaybe',
+ 'link' => $this->baseUrl->get(true) . '/display/' . $item['parent-guid'],
+ 'image' => Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO),
+ 'url' => $item['author-link'],
+ 'text' => $this->l10n->t("%s may attending %s's event", $item['author-name'], $item['parent-author-name']),
+ 'when' => $item['when'],
+ 'ago' => $item['ago'],
+ 'seen' => $item['seen']]);
case Activity::FRIEND:
if (!isset($item['object'])) {
- return new \Friendica\Object\Notification\Notification(
- 'friend',
- $item['link'],
- $item['image'],
- $item['url'],
- $item['text'],
- $item['when'] ?? '',
- $item['ago'] ?? '',
- $item['seen'] ?? false);
+ return new \Friendica\Object\Notification\Notification([
+ 'label' => 'friend',
+ 'link' => $item['link'],
+ 'image' => $item['image'],
+ 'url' => $item['url'],
+ 'text' => $item['text'],
+ 'when' => $item['when'],
+ 'ago' => $item['ago'],
+ 'seen' => $item['seen']]);
}
$xmlHead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
$obj = XML::parseString($xmlHead . $item['object']);
$item['fname'] = $obj->title;
- return new \Friendica\Object\Notification\Notification(
- 'friend',
- $this->baseUrl->get(true) . '/display/' . $item['parent-guid'],
- Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO),
- $item['author-link'],
- $this->l10n->t("%s is now friends with %s", $item['author-name'], $item['fname']),
- $item['when'] ?? '',
- $item['ago'] ?? '',
- $item['seen'] ?? false);
+ return new \Friendica\Object\Notification\Notification([
+ 'label' => 'friend',
+ 'link' => $this->baseUrl->get(true) . '/display/' . $item['parent-guid'],
+ 'image' => Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO),
+ 'url' => $item['author-link'],
+ 'text' => $this->l10n->t("%s is now friends with %s", $item['author-name'], $item['fname']),
+ 'when' => $item['when'],
+ 'ago' => $item['ago'],
+ 'seen' => $item['seen']]);
default:
- return new \Friendica\Object\Notification\Notification(
- $item['label'],
- $item['link'],
- $item['image'],
- $item['url'],
- $item['text'],
- $item['when'] ?? '',
- $item['ago'] ?? '',
- $item['seen'] ?? false);
+ return new \Friendica\Object\Notification\Notification($item);
break;
}
}
$notifications = $this->notification->select($conditions, $params);
foreach ($notifications as $notification) {
- $formattedNotifications[] = new \Friendica\Object\Notification\Notification(
- 'notification',
- $this->baseUrl->get(true) . '/notification/view/' . $notification->id,
- Proxy::proxifyUrl($notification->photo, false, Proxy::SIZE_MICRO),
- $notification->url,
- strip_tags(BBCode::convert($notification->msg)),
- DateTimeFormat::local($notification->date, 'r'),
- Temporal::getRelativeDate($notification->date),
- $notification->seen);
+ $formattedNotifications[] = new \Friendica\Object\Notification\Notification([
+ 'label' => 'notification',
+ 'link' => $this->baseUrl->get(true) . '/notification/view/' . $notification->id,
+ 'image' => Proxy::proxifyUrl($notification->photo, false, Proxy::SIZE_MICRO),
+ 'url' => $notification->url,
+ 'text' => strip_tags(BBCode::convert($notification->msg)),
+ 'when' => DateTimeFormat::local($notification->date, 'r'),
+ 'ago' => Temporal::getRelativeDate($notification->date),
+ 'seen' => $notification->seen]);
}
} catch (Exception $e) {
$this->logger->warning('Select failed.', ['conditions' => $conditions, 'exception' => $e]);
{
/** @var \Friendica\Repository\Notification */
private $repo;
- /** @var $this */
- private $parentInst;
public function __construct(Database $dba, LoggerInterface $logger, \Friendica\Repository\Notification $repo, array $data = [])
{
}
}
- public function __get($name)
- {
- $this->checkValid();
-
- $return = null;
-
- switch ($name) {
- case 'parent':
- if (!empty($this->parent)) {
- $this->parentInst = $this->parentInst ?? $this->repo->getByID($this->parent);
-
- $return = $this->parentInst;
- }
- break;
- default:
- $return = parent::__get($name);
- break;
- }
-
- return $return;
- }
-
public function __set($name, $value)
{
parent::__set($name, $value);
$all = DI::args()->get(2) == 'all';
$notifications = [
- 'ident' => 'introductions',
+ 'ident' => 'introductions',
'notifications' => DI::factNotIntro()->getIntroList($all, self::$firstItemNum, self::ITEMS_PER_PAGE, $id),
];
// There are two kind of introduction. Contacts suggested by other contacts and normal connection requests.
// We have to distinguish between these two because they use different data.
- switch ($notification['label']) {
+ switch ($notification->getLabel()) {
case 'friend_suggestion':
$notificationContent[] = Renderer::replaceMacros($notificationSuggestions, [
- '$type' => $notification->getLabel(),
- 'str_notification_type' => DI::l10n()->t('Notification type:'),
- 'str_type' => $notification->getType(),
- '$intro_id' => $notification->getIntroId(),
- '$lbl_madeby' => DI::l10n()->t('Suggested by:'),
- '$madeby' => $notification->getMadeBy(),
- '$madeby_url' => $notification->getMadeByUrl(),
- '$madeby_zrl' => $notification->getMadeByZrl(),
- '$madeby_addr' => $notification->getMadeByAddr(),
- '$contact_id' => $notification->getContactId(),
- '$photo' => $notification->getPhoto(),
- '$fullname' => $notification->getName(),
- '$url' => $notification->getUrl(),
- '$zrl' => $notification->getZrl(),
- '$lbl_url' => DI::l10n()->t('Profile URL'),
- '$addr' => $notification->getAddr(),
- '$hidden' => ['hidden', DI::l10n()->t('Hide this contact from others'), $notification->isHidden(), ''],
- '$knowyou' => $notification->getKnowYou(),
- '$approve' => DI::l10n()->t('Approve'),
- '$note' => $notification->getNote(),
- '$request' => $notification->getRequest(),
- '$ignore' => DI::l10n()->t('Ignore'),
- '$discard' => DI::l10n()->t('Discard'),
+ '$type' => $notification->getLabel(),
+ '$str_notification_type' => DI::l10n()->t('Notification type:'),
+ '$str_type' => $notification->getType(),
+ '$intro_id' => $notification->getIntroId(),
+ '$lbl_madeby' => DI::l10n()->t('Suggested by:'),
+ '$madeby' => $notification->getMadeBy(),
+ '$madeby_url' => $notification->getMadeByUrl(),
+ '$madeby_zrl' => $notification->getMadeByZrl(),
+ '$madeby_addr' => $notification->getMadeByAddr(),
+ '$contact_id' => $notification->getContactId(),
+ '$photo' => $notification->getPhoto(),
+ '$fullname' => $notification->getName(),
+ '$url' => $notification->getUrl(),
+ '$zrl' => $notification->getZrl(),
+ '$lbl_url' => DI::l10n()->t('Profile URL'),
+ '$addr' => $notification->getAddr(),
+ '$hidden' => ['hidden', DI::l10n()->t('Hide this contact from others'), $notification->isHidden(), ''],
+ '$knowyou' => $notification->getKnowYou(),
+ '$approve' => DI::l10n()->t('Approve'),
+ '$note' => $notification->getNote(),
+ '$request' => $notification->getRequest(),
+ '$ignore' => DI::l10n()->t('Ignore'),
+ '$discard' => DI::l10n()->t('Discard'),
]);
break;
$lbl_knowyou = DI::l10n()->t('Claims to be known to you: ');
$knowyou = ($notification->getKnowYou() ? DI::l10n()->t('yes') : DI::l10n()->t('no'));
$helptext = DI::l10n()->t('Shall your connection be bidirectional or not?');
- $helptext2 = DI::l10n()->t('Accepting %s as a friend allows %s to subscribe to your posts, and you will also receive updates from them in your news feed.', $notification['name'], $notification['name']);
- $helptext3 = DI::l10n()->t('Accepting %s as a subscriber allows them to subscribe to your posts, but you will not receive updates from them in your news feed.', $notification['name']);
+ $helptext2 = DI::l10n()->t('Accepting %s as a friend allows %s to subscribe to your posts, and you will also receive updates from them in your news feed.', $notification->getName(), $notification->getName());
+ $helptext3 = DI::l10n()->t('Accepting %s as a subscriber allows them to subscribe to your posts, but you will not receive updates from them in your news feed.', $notification->getName());
} elseif ($notification->getNetwork() === Protocol::DIASPORA) {
$helptext = DI::l10n()->t('Shall your connection be bidirectional or not?');
- $helptext2 = DI::l10n()->t('Accepting %s as a friend allows %s to subscribe to your posts, and you will also receive updates from them in your news feed.', $notification['name'], $notification['name']);
- $helptext3 = DI::l10n()->t('Accepting %s as a sharer allows them to subscribe to your posts, but you will not receive updates from them in your news feed.', $notification['name']);
+ $helptext2 = DI::l10n()->t('Accepting %s as a friend allows %s to subscribe to your posts, and you will also receive updates from them in your news feed.', $notification->getName(), $notification->getName());
+ $helptext3 = DI::l10n()->t('Accepting %s as a sharer allows them to subscribe to your posts, but you will not receive updates from them in your news feed.', $notification->getName());
}
$dfrn_tpl = Renderer::getMarkupTemplate('notifications/netfriend.tpl');
$action = 'dfrn_confirm';
}
- $header = $notification['name'];
+ $header = $notification->getName();
- if ($notification['addr'] != '') {
- $header .= ' <' . $notification['addr'] . '>';
+ if ($notification->getAddr() != '') {
+ $header .= ' <' . $notification->getAddr() . '>';
}
$header .= ' (' . ContactSelector::networkToName($notification->getNetwork(), $notification->getUrl()) . ')';
}
$notificationContent[] = Renderer::replaceMacros($notificationTemplate, [
- '$type' => $notification->getLabel(),
- '$header' => $header,
- 'str_notification_type' => DI::l10n()->t('Notification type:'),
- 'str_type' => $notification->getType(),
- '$dfrn_text' => $dfrn_text,
- '$dfrn_id' => $notification->getDfrnId(),
- '$uid' => $notification->getUid(),
- '$intro_id' => $notification->getIntroId(),
- '$contact_id' => $notification->getContactId(),
- '$photo' => $notification->getPhoto(),
- '$fullname' => $notification->getName(),
- '$location' => $notification->getLocation(),
- '$lbl_location' => DI::l10n()->t('Location:'),
- '$about' => $notification->getAbout(),
- '$lbl_about' => DI::l10n()->t('About:'),
- '$keywords' => $notification->getKeywords(),
- '$lbl_keywords' => DI::l10n()->t('Tags:'),
- '$gender' => $notification->getGender(),
- '$lbl_gender' => DI::l10n()->t('Gender:'),
- '$hidden' => ['hidden', DI::l10n()->t('Hide this contact from others'), ($notification['hidden'] == 1), ''],
- '$url' => $notification->getUrl(),
- '$zrl' => $notification->getZrl(),
- '$lbl_url' => DI::l10n()->t('Profile URL'),
- '$addr' => $notification->getAddr(),
- '$lbl_knowyou' => $lbl_knowyou,
- '$lbl_network' => DI::l10n()->t('Network:'),
- '$network' => ContactSelector::networkToName($notification->getNetwork(), $notification->getUrl()),
- '$knowyou' => $knowyou,
- '$approve' => DI::l10n()->t('Approve'),
- '$note' => $notification->getNote(),
- '$ignore' => DI::l10n()->t('Ignore'),
- '$discard' => $discard,
- '$action' => $action,
+ '$type' => $notification->getLabel(),
+ '$header' => $header,
+ '$str_notification_type' => DI::l10n()->t('Notification type:'),
+ '$str_type' => $notification->getType(),
+ '$dfrn_text' => $dfrn_text,
+ '$dfrn_id' => $notification->getDfrnId(),
+ '$uid' => $notification->getUid(),
+ '$intro_id' => $notification->getIntroId(),
+ '$contact_id' => $notification->getContactId(),
+ '$photo' => $notification->getPhoto(),
+ '$fullname' => $notification->getName(),
+ '$location' => $notification->getLocation(),
+ '$lbl_location' => DI::l10n()->t('Location:'),
+ '$about' => $notification->getAbout(),
+ '$lbl_about' => DI::l10n()->t('About:'),
+ '$keywords' => $notification->getKeywords(),
+ '$lbl_keywords' => DI::l10n()->t('Tags:'),
+ '$gender' => $notification->getGender(),
+ '$lbl_gender' => DI::l10n()->t('Gender:'),
+ '$hidden' => ['hidden', DI::l10n()->t('Hide this contact from others'), $notification->isHidden(), ''],
+ '$url' => $notification->getUrl(),
+ '$zrl' => $notification->getZrl(),
+ '$lbl_url' => DI::l10n()->t('Profile URL'),
+ '$addr' => $notification->getAddr(),
+ '$lbl_knowyou' => $lbl_knowyou,
+ '$lbl_network' => DI::l10n()->t('Network:'),
+ '$network' => ContactSelector::networkToName($notification->getNetwork(), $notification->getUrl()),
+ '$knowyou' => $knowyou,
+ '$approve' => DI::l10n()->t('Approve'),
+ '$note' => $notification->getNote(),
+ '$ignore' => DI::l10n()->t('Ignore'),
+ '$discard' => $discard,
+ '$action' => $action,
]);
break;
}
/** @var string */
private $type = '';
/** @var integer */
- private $intro_id = 0;
+ private $intro_id = -1;
/** @var string */
private $madeBy = '';
/** @var string */
/** @var string */
private $madeByAddr = '';
/** @var integer */
- private $contactId = 0;
+ private $contactId = -1;
/** @var string */
private $photo = '';
/** @var string */
/** @var boolean */
private $hidden = false;
/** @var integer */
- private $postNewFriend = 0;
- /** @var string */
- private $knowYou = '';
+ private $postNewFriend = -1;
+ /** @var boolean */
+ private $knowYou = false;
/** @var string */
private $note = '';
/** @var string */
private $request = '';
+ /** @var int */
+ private $dfrnId = -1;
/** @var string */
- private $dfrnId;
- /** @var string */
- private $addr;
+ private $addr = '';
/** @var string */
- private $network;
+ private $network = '';
/** @var int */
- private $uid;
+ private $uid = -1;
/** @var string */
- private $keywords;
+ private $keywords = '';
/** @var string */
- private $gender;
+ private $gender = '';
/** @var string */
- private $location;
+ private $location = '';
/** @var string */
- private $about;
+ private $about = '';
/**
* @return string
public function __construct(array $data = [])
{
$this->label = $data['label'] ?? '';
- $this->type = $data['str_$type'] ?? '';
- $this->intro_id = $data['$intro_id'] ?? '';
- $this->madeBy = $data['$madeBy'] ?? '';
- $this->madeByUrl = $data['$madeByUrl'] ?? '';
- $this->madeByZrl = $data['$madeByZrl'] ?? '';
- $this->madeByAddr = $data['$madeByAddr'] ?? '';
- $this->contactId = $data['$contactId'] ?? '';
- $this->photo = $data['$photo'] ?? '';
- $this->name = $data['$name'] ?? '';
- $this->url = $data['$url'] ?? '';
- $this->zrl = $data['$zrl'] ?? '';
- $this->hidden = $data['$hidden'] ?? '';
- $this->postNewFriend = $data['$postNewFriend'] ?? '';
- $this->knowYou = $data['$knowYou'] ?? '';
- $this->note = $data['$note'] ?? '';
- $this->request = $data['$request'] ?? '';
- $this->dfrnId = $data['dfrn_id'] ?? '';
+ $this->type = $data['str_type'] ?? '';
+ $this->intro_id = $data['$intro_id'] ?? -1;
+ $this->madeBy = $data['madeBy'] ?? '';
+ $this->madeByUrl = $data['madeByUrl'] ?? '';
+ $this->madeByZrl = $data['madeByZrl'] ?? '';
+ $this->madeByAddr = $data['madeByAddr'] ?? '';
+ $this->contactId = $data['contactId'] ?? '';
+ $this->photo = $data['photo'] ?? '';
+ $this->name = $data['name'] ?? '';
+ $this->url = $data['url'] ?? '';
+ $this->zrl = $data['zrl'] ?? '';
+ $this->hidden = $data['hidden'] ?? false;
+ $this->postNewFriend = $data['postNewFriend'] ?? '';
+ $this->knowYou = $data['knowYou'] ?? false;
+ $this->note = $data['note'] ?? '';
+ $this->request = $data['request'] ?? '';
+ $this->dfrnId = $data['dfrn_id'] ?? -1;
$this->addr = $data['addr'] ?? '';
$this->network = $data['network'] ?? '';
- $this->uid = $data['uid'] ?? '';
+ $this->uid = $data['uid'] ?? -1;
$this->keywords = $data['keywords'] ?? '';
$this->gender = $data['gender'] ?? '';
$this->location = $data['location'] ?? '';
return $this->seen;
}
- public function __construct(string $label = '', string $link = '', string $image = '',
- string $url = '', string $text = '',
- string $when = '', string $ago = '', bool $seen = false)
+ public function __construct(array $data)
{
- $this->label = $label;
- $this->link = $link;
- $this->image = $image;
- $this->url = $url;
- $this->text = $text;
- $this->when = $when;
- $this->ago = $ago;
- $this->seen = $seen;
+ $this->label = $data['label'] ?? '';
+ $this->link = $data['link'] ?? '';
+ $this->image = $data['image'] ?? '';
+ $this->url = $data['url'] ?? '';
+ $this->text = $data['text'] ?? '';
+ $this->when = $data['when'] ?? '';
+ $this->ago = $data['ago'] ?? '';
+ $this->seen = $data['seen'] ?? false;
}
/**