- logger('notifier: '.$target_item["guid"].' dfrndelivery: '.$contact['name']);
-
- if ($mail) {
- $item['body'] = Item::fixPrivatePhotos($item['body'], $owner['uid'], null, $item['contact-id']);
- $atom = DFRN::mail($item, $owner);
- } elseif ($fsuggest) {
- $atom = DFRN::fsuggest($item, $owner);
- q("DELETE FROM `fsuggest` WHERE `id` = %d LIMIT 1", intval($item['id']));
- } elseif ($relocate) {
- $atom = DFRN::relocate($owner, $uid);
- } elseif ($followup) {
- $msgitems = [];
- foreach ($items as $item) { // there is only one item
- if (!$item['parent']) {
- return;
- }
- if ($item['id'] == $item_id) {
- logger('followup: item: '. print_r($item,true), LOGGER_DATA);
- $msgitems[] = $item;
- }
- }
- $atom = DFRN::entries($msgitems,$owner);
- } else {
- $msgitems = [];
- foreach ($items as $item) {
- if (!$item['parent']) {
- return;
- }
-
- // private emails may be in included in public conversations. Filter them.
- if ($public_message && $item['private']) {
- return;
- }
-
- $item_contact = self::getItemContact($item,$icontacts);
- if (!$item_contact) {
- return;
- }
-
- if ($normal_mode) {
- // Only add the parent when we don't delete other items.
- if ($item_id == $item['id'] || (($item['id'] == $item['parent']) && ($cmd != 'drop'))) {
- $item["entry:comment-allow"] = true;
- $item["entry:cid"] = (($top_level) ? $contact['id'] : 0);
- $msgitems[] = $item;
- }
- } else {
- $item["entry:comment-allow"] = true;
- $msgitems[] = $item;
- }
- }
- $atom = DFRN::entries($msgitems,$owner);
- }
-
- logger('notifier entry: '.$contact["url"].' '.$target_item["guid"].' entry: '.$atom, LOGGER_DEBUG);
-
- logger('notifier: '.$atom, LOGGER_DATA);
- $basepath = implode('/', array_slice(explode('/',$contact['url']),0,3));
-
- // perform local delivery if we are on the same site
-
- if (link_compare($basepath,System::baseUrl())) {
- $nickname = basename($contact['url']);
- if ($contact['issued-id']) {
- $sql_extra = sprintf(" AND `dfrn-id` = '%s' ", dbesc($contact['issued-id']));
- } else {
- $sql_extra = sprintf(" AND `issued-id` = '%s' ", dbesc($contact['dfrn-id']));
- }
-
- $x = q("SELECT `contact`.*, `contact`.`uid` AS `importer_uid`,
- `contact`.`pubkey` AS `cpubkey`,
- `contact`.`prvkey` AS `cprvkey`,
- `contact`.`thumb` AS `thumb`,
- `contact`.`url` as `url`,
- `contact`.`name` as `senderName`,
- `user`.*
- FROM `contact`
- INNER JOIN `user` ON `contact`.`uid` = `user`.`uid`
- WHERE `contact`.`blocked` = 0 AND `contact`.`pending` = 0
- AND `contact`.`network` = '%s' AND `user`.`nickname` = '%s'
- $sql_extra
- AND `user`.`account_expired` = 0 AND `user`.`account_removed` = 0 LIMIT 1",
- dbesc(NETWORK_DFRN),
- dbesc($nickname)
- );
-
- if ($x && count($x)) {
- $write_flag = ((($x[0]['rel']) && ($x[0]['rel'] != CONTACT_IS_SHARING)) ? true : false);
- if ((($owner['page-flags'] == PAGE_COMMUNITY) || $write_flag) && !$x[0]['writable']) {
- q("UPDATE `contact` SET `writable` = 1 WHERE `id` = %d",
- intval($x[0]['id'])
- );
- $x[0]['writable'] = 1;
- }
-
- $ssl_policy = Config::get('system','ssl_policy');
- $x[0] = Contact::updateSslPolicy($x[0], $ssl_policy);
-
- // If we are setup as a soapbox we aren't accepting top level posts from this person
-
- if (($x[0]['page-flags'] == PAGE_SOAPBOX) && $top_level) {
- break;
- }
- logger('mod-delivery: local delivery');
- DFRN::import($atom, $x[0]);
- break;
- }
- }
-
- if (!Queue::wasDelayed($contact['id'])) {
- $deliver_status = DFRN::deliver($owner, $contact, $atom);
- } else {
- $deliver_status = (-1);
- }
-
- logger('notifier: dfrn_delivery to '.$contact["url"].' with guid '.$target_item["guid"].' returns '.$deliver_status);
-
- if ($deliver_status < 0) {
- logger('notifier: delivery failed: queuing message');
- Queue::add($contact['id'], NETWORK_DFRN, $atom, false, $target_item['guid']);
-
- // The message could not be delivered. We mark the contact as "dead"
- Contact::markForArchival($contact);
- } else {
- // We successfully delivered a message, the contact is alive
- Contact::unmarkForArchival($contact);
- }