]> git.mxchange.org Git - friendica.git/commitdiff
receive friendship suggestion over the wire (dfrn) and store
authorFriendika <info@friendika.com>
Thu, 23 Jun 2011 02:08:30 +0000 (19:08 -0700)
committerFriendika <info@friendika.com>
Thu, 23 Jun 2011 02:08:30 +0000 (19:08 -0700)
boot.php
mod/dfrn_notify.php

index 9700c012ddcea98d31c13ad738249cade080889e..c5751da37330adead686161bffe0076eb4e5e3be 100644 (file)
--- 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      );
 
index 8f11cabf44d7c360f20e1c357439f67177b2d9de..f6d1f2be57c4e42fbc73b9a19e289f5498345714 100644 (file)
@@ -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' );