From c23c366ff68f8b030c6db23e7edb2f6b21fbd5aa Mon Sep 17 00:00:00 2001 From: Friendika Date: Wed, 22 Jun 2011 19:08:30 -0700 Subject: receive friendship suggestion over the wire (dfrn) and store --- boot.php | 2 +- mod/dfrn_notify.php | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 72 insertions(+), 2 deletions(-) diff --git a/boot.php b/boot.php index 9700c012d..c5751da37 100644 --- a/boot.php +++ b/boot.php @@ -4,7 +4,7 @@ set_time_limit(0); ini_set('pcre.backtrack_limit', 250000); -define ( 'FRIENDIKA_VERSION', '2.2.1018' ); +define ( 'FRIENDIKA_VERSION', '2.2.1019' ); define ( 'DFRN_PROTOCOL_VERSION', '2.21' ); define ( 'DB_UPDATE_VERSION', 1066 ); diff --git a/mod/dfrn_notify.php b/mod/dfrn_notify.php index 8f11cabf4..f6d1f2be5 100644 --- a/mod/dfrn_notify.php +++ b/mod/dfrn_notify.php @@ -144,7 +144,7 @@ function dfrn_notify_post(&$a) { } // Consume notification feed. This may differ from consuming a public feed in several ways - // - might contain email + // - might contain email or friend suggestions // - might contain remote followup to our message // - in which case we need to accept it and then notify other conversants // - we may need to send various email notifications @@ -154,6 +154,76 @@ function dfrn_notify_post(&$a) { $feed->enable_order_by_date(false); $feed->init(); + // handle friend suggestion notification + + $sugg = $feed->get_feed_tags( NAMESPACE_DFRN, 'suggest' ); + if(isset($sugg[0]['child'][NAMESPACE_DFRN])) { + $base = $sugg[0]['child'][NAMESPACE_DFRN]; + $fsugg = array(); + $fsugg['uid'] = $importer['importer_uid']; + $fsugg['cid'] = $importer['id']; + $fsugg['name'] = notags(unxmlify($base['name'][0]['data'])); + $fsugg['photo'] = notags(unxmlify($base['photo'][0]['data'])); + $fsugg['url'] = notags(unxmlify($base['url'][0]['data'])); + $fsugg['body'] = escape_tags(unxmlify($base['note'][0]['data'])); + + // Does our member already have a friend matching this description? + + $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `url` = '%s' AND `uid` = %d LIMIT 1", + dbesc($fsugg['name']), + dbesc($fsuff['url']), + intval($fsugg['uid']) + ); + if(count($r)) + xml_status(0); + + // Do we already have an fcontact record for this person? + + $fid = 0; + $r = q("SELECT * FROM `fcontact` WHERE `url` = '%s' AND `name` = '%s' AND `photo` = '%s' LIMIT 1", + dbesc($fsugg['url']), + dbesc($fsuff['name']), + dbesc($fsugg['photo']) + ); + if(count($r)) { + $fid = $r[0]['id']; + } + if(! $fid) + $r = q("INSERT INTO `fcontact` ( `name`,`url`,`photo` ) VALUES ( '%s', '%s', '%s' ) ", + dbesc($fsuff['name']), + dbesc($fsugg['url']), + dbesc($fsugg['photo']) + ); + $r = q("SELECT * FROM `fcontact` WHERE `url` = '%s' AND `name` = '%s' AND `photo` = '%s' LIMIT 1", + dbesc($fsugg['url']), + dbesc($fsuff['name']), + dbesc($fsugg['photo']) + ); + if(count($r)) { + $fid = $r[0]['id']; + } + // database record did not get created. Quietly give up. + else + xml_status(0); + + $hash = random_string(); + + $r = q("INSERT INTO `intro` ( `uid`, `fid`, `contact-id`, `note`, `hash`, `datetime`, `blocked` ) + VALUES( %d, %d, %d, '%s', '%s', '%s', %d )", + intval($fsugg['uid']), + intval($fid), + intval($fsugg['cid']), + dbesc($fsugg['body']), + dbesc($hash), + dbesc(datetime_convert()), + intval(0) + ); + + // TODO - send email notify (which may require a new notification preference) + + xml_status(0); + } + $ismail = false; $rawmail = $feed->get_feed_tags( NAMESPACE_DFRN, 'mail' ); -- cgit v1.2.3