-
-
- $deliver_status = 0;
-
- logger("main delivery by notifier: followup=$followup mail=$mail fsuggest=$fsuggest relocate=$relocate");
-
- switch($contact['network']) {
- case NETWORK_DFRN:
-
- // perform local delivery if we are on the same site
-
- $basepath = implode('/', array_slice(explode('/',$contact['url']),0,3));
-
- if(link_compare($basepath,$a->get_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`.`archive` = 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;
- }
-
- // if contact's ssl policy changed, which we just determined
- // is on our own server, update our contact links
-
- $ssl_policy = get_config('system','ssl_policy');
- fix_contact_ssl_policy($x[0],$ssl_policy);
-
- // If we are setup as a soapbox we aren't accepting input from this person
-
- if($x[0]['page-flags'] == PAGE_SOAPBOX)
- break;
-
- require_once('library/simplepie/simplepie.inc');
- logger('mod-delivery: local delivery');
- local_delivery($x[0],$atom);
- break;
- }
- }
-
- logger('notifier: dfrndelivery: ' . $contact['name']);
- $deliver_status = dfrn_deliver($owner,$contact,$atom);
-
- logger('notifier: dfrn_delivery returns ' . $deliver_status);
-
- if($deliver_status == (-1)) {
- logger('notifier: delivery failed: queuing message');
- // queue message for redelivery
- add_to_queue($contact['id'],NETWORK_DFRN,$atom);
- }
- break;
- case NETWORK_OSTATUS:
-
- // Do not send to ostatus if we are not configured to send to public networks
- if($owner['prvnets'])
- break;
-
- if(get_config('system','ostatus_disabled') || get_config('system','dfrn_only'))
- break;
-
- if($followup && $contact['notify']) {
- logger('slapdelivery followup item '.$item_id.' to ' . $contact['name']);
- $deliver_status = slapper($owner,$contact['notify'],$slap);
-
- if($deliver_status == (-1)) {
- // queue message for redelivery
- add_to_queue($contact['id'],NETWORK_OSTATUS,$slap);
- }
- } else {
-
- // only send salmon if public - e.g. if it's ok to notify
- // a public hub, it's ok to send a salmon
-
- if((count($slaps)) && ($public_message) && (! $expire)) {
- logger('slapdelivery item '.$item_id.' to ' . $contact['name']);
- foreach($slaps as $slappy) {
- if($contact['notify']) {
- $deliver_status = slapper($owner,$contact['notify'],$slappy);
- if($deliver_status == (-1)) {
- // queue message for redelivery
- add_to_queue($contact['id'],NETWORK_OSTATUS,$slappy);
- }
- }
- }
- }
- }
- break;
-
- case NETWORK_MAIL:
- case NETWORK_MAIL2:
-
- if(get_config('system','dfrn_only'))
- break;
-
- // WARNING: does not currently convert to RFC2047 header encodings, etc.
-
- $addr = $contact['addr'];
- if(! strlen($addr))
- break;
-
- if($cmd === 'wall-new' || $cmd === 'comment-new') {
-
- $it = null;
- if($cmd === 'wall-new')
- $it = $items[0];
- else {
- $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
- intval($argv[2]),
- intval($uid)
- );
- if(count($r))
- $it = $r[0];
- }
- if(! $it)
- break;
-
-
-
- $local_user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
- intval($uid)
- );
- if(! count($local_user))
- break;
-
- $reply_to = '';
- $r1 = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1",
- intval($uid)
- );
- if($r1 && $r1[0]['reply_to'])
- $reply_to = $r1[0]['reply_to'];
-
- $subject = (($it['title']) ? email_header_encode($it['title'],'UTF-8') : t("\x28no subject\x29")) ;
-
- // only expose our real email address to true friends
- if(($contact['rel'] == CONTACT_IS_FRIEND) && (! $contact['blocked']))
- if($reply_to) {
- $headers = 'From: ' . email_header_encode($local_user[0]['username'],'UTF-8') . ' <' . $reply_to . '>' . "\n";
- $headers .= 'Sender: '.$local_user[0]['email']."\n";
- } else
- $headers = 'From: ' . email_header_encode($local_user[0]['username'],'UTF-8') . ' <' . $local_user[0]['email'] . '>' . "\n";
- else
- $headers = 'From: ' . email_header_encode($local_user[0]['username'],'UTF-8') . ' <' . t('noreply') . '@' . $a->get_hostname() . '>' . "\n";
-
- //if($reply_to)
- // $headers .= 'Reply-to: ' . $reply_to . "\n";
-
- $headers .= 'Message-Id: <' . iri2msgid($it['uri']) . '>' . "\n";
-
- if($it['uri'] !== $it['parent-uri']) {
- $headers .= "References: <".iri2msgid($it["parent-uri"]).">";
-
- // If Threading is enabled, write down the correct parent
- if (($it["thr-parent"] != "") and ($it["thr-parent"] != $it["parent-uri"]))
- $headers .= " <".iri2msgid($it["thr-parent"]).">";
- $headers .= "\n";
-
- if(!$it['title']) {
- $r = q("SELECT `title` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
- dbesc($it['parent-uri']),
- intval($uid));
-
- if(count($r) AND ($r[0]['title'] != ''))
- $subject = $r[0]['title'];
- else {
- $r = q("SELECT `title` FROM `item` WHERE `parent-uri` = '%s' AND `uid` = %d LIMIT 1",
- dbesc($it['parent-uri']),
- intval($uid));
-
- if(count($r) AND ($r[0]['title'] != ''))
- $subject = $r[0]['title'];
- }
- }
- if(strncasecmp($subject,'RE:',3))
- $subject = 'Re: '.$subject;
- }
- email_send($addr, $subject, $headers, $it);
- }
- break;
- case NETWORK_DIASPORA:
- require_once('include/diaspora.php');
-
- if(get_config('system','dfrn_only') || (! get_config('system','diaspora_enabled')))
- break;
-
- if($mail) {
- diaspora_send_mail($item,$owner,$contact);
- break;
- }
-
- if(! $normal_mode)
- break;
-
- // special handling for followup to public post
- // all other public posts processed as public batches further below
-
- if($public_message) {
- if($followup)
- diaspora_send_followup($target_item,$owner,$contact, true);
- break;
- }
-
- if(! $contact['pubkey'])
- break;
-
- if($target_item['verb'] === ACTIVITY_DISLIKE) {
- // unsupported
- break;
- }
- elseif(($target_item['deleted']) && (($target_item['uri'] === $target_item['parent-uri']) || $followup)) {
- // send both top-level retractions and relayable retractions for owner to relay
- diaspora_send_retraction($target_item,$owner,$contact);
- break;
- }
- elseif($followup) {
- // send comments and likes to owner to relay
- diaspora_send_followup($target_item,$owner,$contact);
- break;
- }
- elseif($target_item['uri'] !== $target_item['parent-uri']) {
- // we are the relay - send comments, likes and relayable_retractions
- // (of comments and likes) to our conversants
- diaspora_send_relay($target_item,$owner,$contact);
- break;
- }
- elseif(($top_level) && (! $walltowall)) {
- // currently no workable solution for sending walltowall
- diaspora_send_status($target_item,$owner,$contact);
- break;
- }
-
- break;
-
- case NETWORK_FEED:
- case NETWORK_FACEBOOK:
- if(get_config('system','dfrn_only'))
- break;
- case NETWORK_PUMPIO:
- if(get_config('system','dfrn_only'))
- break;
- default:
- break;