aboutsummaryrefslogtreecommitdiffstats
path: root/mod/dfrn_notify.php
diff options
context:
space:
mode:
authorFriendika <info@friendika.com>2011-06-22 19:08:30 -0700
committerFriendika <info@friendika.com>2011-06-22 19:08:30 -0700
commitc23c366ff68f8b030c6db23e7edb2f6b21fbd5aa (patch)
tree701aded59c7b26c0a6e841c928952bd3d0e86ce6 /mod/dfrn_notify.php
parent673e51826c0629db1966e460630227c95739a46d (diff)
downloadvolse-hubzilla-c23c366ff68f8b030c6db23e7edb2f6b21fbd5aa.tar.gz
volse-hubzilla-c23c366ff68f8b030c6db23e7edb2f6b21fbd5aa.tar.bz2
volse-hubzilla-c23c366ff68f8b030c6db23e7edb2f6b21fbd5aa.zip
receive friendship suggestion over the wire (dfrn) and store
Diffstat (limited to 'mod/dfrn_notify.php')
-rw-r--r--mod/dfrn_notify.php72
1 files changed, 71 insertions, 1 deletions
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' );