]> git.mxchange.org Git - friendica.git/blobdiff - mod/dfrn_confirm.php
Merge branch 'master' of git://github.com/friendica/friendica
[friendica.git] / mod / dfrn_confirm.php
index 180e8ff31c7a587ab5eb1770a7b8de3d2f45cf60..0bc3ea7df597550f96286b8210fc6925da788876 100644 (file)
@@ -71,12 +71,16 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
                        $dfrn_id   = $handsfree['dfrn_id'];
                        $intro_id  = $handsfree['intro_id'];
                        $duplex    = $handsfree['duplex'];
+                       $hidden    = ((array_key_exists('hidden',$handsfree)) ? intval($handsfree['hidden']) : 0 );
+                       $activity  = ((array_key_exists('activity',$handsfree)) ? intval($handsfree['activity']) : 0 );
                }
                else {
                        $dfrn_id  = ((x($_POST,'dfrn_id'))    ? notags(trim($_POST['dfrn_id'])) : "");
                        $intro_id = ((x($_POST,'intro_id'))   ? intval($_POST['intro_id'])      : 0 );
                        $duplex   = ((x($_POST,'duplex'))     ? intval($_POST['duplex'])        : 0 );
                        $cid      = ((x($_POST,'contact_id')) ? intval($_POST['contact_id'])    : 0 );
+                       $hidden   = ((x($_POST,'hidden'))     ? intval($_POST['hidden'])        : 0 );
+                       $activity = ((x($_POST,'activity'))   ? intval($_POST['activity'])      : 0 );
                }
 
                /**
@@ -103,7 +107,7 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
                 *
                 */
 
-               $r = q("SELECT * FROM `contact` WHERE ( ( `issued-id` != '' AND `issued-id` = '%s' ) OR ( `id` = %d AND `id` != 0 ) ) AND `uid` = %d LIMIT 1",
+               $r = q("SELECT * FROM `contact` WHERE ( ( `issued-id` != '' AND `issued-id` = '%s' ) OR ( `id` = %d AND `id` != 0 ) ) AND `uid` = %d AND `duplex` = 0 LIMIT 1",
                        dbesc($dfrn_id),
                        intval($cid),
                        intval($uid)
@@ -112,6 +116,7 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
                if(! count($r)) {
                        logger('dfrn_confirm: Contact not found in DB.'); 
                        notice( t('Contact not found.') . EOL );
+                       notice( t('This may occasionally happen if contact was requested by both persons and it has already been approved.') . EOL );
                        return;
                }
 
@@ -122,7 +127,7 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
                $site_pubkey  = $contact['site-pubkey'];
                $dfrn_confirm = $contact['confirm'];
                $aes_allow    = $contact['aes_allow'];
-
+               
                $network = ((strlen($contact['issued-id'])) ? NETWORK_DFRN : NETWORK_OSTATUS);
 
                if($contact['network'])
@@ -248,7 +253,7 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
                        $message = unxmlify($xml->message);   // human readable text of what may have gone wrong.
                        switch($status) {
                                case 0:
-                                       notice( t("Confirmation completed successfully.") . EOL);
+                                       info( t("Confirmation completed successfully.") . EOL);
                                        if(strlen($message))
                                                notice( t('Remote site reported: ') . $message . EOL);
                                        break;
@@ -316,7 +321,8 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
                        if(($relation == CONTACT_IS_SHARING) && ($duplex))
                                $duplex = 0;
 
-                       $r = q("UPDATE `contact` SET `photo` = '%s', 
+                       $r = q("UPDATE `contact` SET 
+                               `photo` = '%s', 
                                `thumb` = '%s',
                                `micro` = '%s', 
                                `rel` = %d, 
@@ -326,6 +332,7 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
                                `blocked` = 0, 
                                `pending` = 0,
                                `duplex` = %d,
+                               `hidden` = %d,
                                `network` = 'dfrn' WHERE `id` = %d LIMIT 1
                        ",
                                dbesc($photos[0]),
@@ -336,6 +343,7 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
                                dbesc(datetime_convert()),
                                dbesc(datetime_convert()),
                                intval($duplex),
+                               intval($hidden),
                                intval($contact_id)
                        );
                }
@@ -365,6 +373,9 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
                        if($network === NETWORK_DIASPORA) {
                                if($duplex)
                                        $new_relation = CONTACT_IS_FRIEND;
+                               else
+                                       $new_relation = CONTACT_IS_SHARING;
+
                                if($new_relation != CONTACT_IS_FOLLOWER)
                                        $writable = 1;
                        }
@@ -387,6 +398,7 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
                                `pending` = 0,
                                `network` = '%s',
                                `writable` = %d,
+                               `hidden` = %d,
                                `rel` = %d
                                WHERE `id` = %d LIMIT 1
                        ",
@@ -400,6 +412,7 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
                                dbesc($poll),
                                dbesc($network),
                                intval($writable),
+                               intval($hidden),
                                intval($new_relation),
                                intval($contact_id)
                        );                      
@@ -418,63 +431,65 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
                else
                        $contact = null;
 
-               // Send a new friend post if we are allowed to...
+               if(isset($new_relation) && $new_relation == CONTACT_IS_FRIEND) {
 
-               $r = q("SELECT `hide-friends` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
-                       intval($uid)
-               );
-               if((count($r)) && ($r[0]['hide-friends'] == 0) && (is_array($contact)) &&  isset($new_relation) && ($new_relation == CONTACT_IS_FRIEND)) {
-
-                       if($r[0]['network'] === NETWORK_DIASPORA) {
+                       if(($contact) && ($contact['network'] === NETWORK_DIASPORA)) {
                                require_once('include/diaspora.php');
                                $ret = diaspora_share($user[0],$r[0]);
                                logger('mod_follow: diaspora_share returns: ' . $ret);
                        }
 
-                       require_once('include/items.php');
+                       // Send a new friend post if we are allowed to...
 
-                       $self = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
+                       $r = q("SELECT `hide-friends` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
                                intval($uid)
                        );
+                       if((count($r)) && ($activity) && (! $hidden)) {
 
-                       if(count($self)) {
-
-                               $arr = array();
-                               $arr['uri'] = $arr['parent-uri'] = item_new_uri($a->get_hostname(), $uid); 
-                               $arr['uid'] = $uid;
-                               $arr['contact-id'] = $self[0]['id'];
-                               $arr['wall'] = 1;
-                               $arr['type'] = 'wall';
-                               $arr['gravity'] = 0;
-                               $arr['author-name'] = $arr['owner-name'] = $self[0]['name'];
-                               $arr['author-link'] = $arr['owner-link'] = $self[0]['url'];
-                               $arr['author-avatar'] = $arr['owner-avatar'] = $self[0]['thumb'];
-                               $arr['verb'] = ACTIVITY_FRIEND;
-                               $arr['object-type'] = ACTIVITY_OBJ_PERSON;
-                               
-                               $A = '[url=' . $self[0]['url'] . ']' . $self[0]['name'] . '[/url]';
-                               $B = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
-                               $BPhoto = '[url=' . $contact['url'] . ']' . '[img]' . $contact['thumb'] . '[/img][/url]';
-                               $arr['body'] =  sprintf( t('%1$s is now friends with %2$s'), $A, $B)."\n\n\n".$Bphoto;
-
-                               $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $contact['name'] . '</title>'
-                                       . '<id>' . $contact['url'] . '/' . $contact['name'] . '</id>';
-                               $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $contact['url'] . '" />' . "\n");
-                               $arr['object'] .= xmlify('<link rel="photo" type="image/jpeg" href="' . $contact['thumb'] . '" />' . "\n");
-                               $arr['object'] .= '</link></object>' . "\n";
-                               $arr['last-child'] = 1;
-
-                               $arr['allow_cid'] = $user[0]['allow_cid'];
-                               $arr['allow_gid'] = $user[0]['allow_gid'];
-                               $arr['deny_cid']  = $user[0]['deny_cid'];
-                               $arr['deny_gid']  = $user[0]['deny_gid'];
-
-                               $i = item_store($arr);
-                               if($i)
-                               proc_run('php',"include/notifier.php","activity","$i");
+                               require_once('include/items.php');
 
-                       }
+                               $self = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
+                                       intval($uid)
+                               );
 
+                               if(count($self)) {
+
+                                       $arr = array();
+                                       $arr['uri'] = $arr['parent-uri'] = item_new_uri($a->get_hostname(), $uid); 
+                                       $arr['uid'] = $uid;
+                                       $arr['contact-id'] = $self[0]['id'];
+                                       $arr['wall'] = 1;
+                                       $arr['type'] = 'wall';
+                                       $arr['gravity'] = 0;
+                                       $arr['origin'] = 1;
+                                       $arr['author-name'] = $arr['owner-name'] = $self[0]['name'];
+                                       $arr['author-link'] = $arr['owner-link'] = $self[0]['url'];
+                                       $arr['author-avatar'] = $arr['owner-avatar'] = $self[0]['thumb'];
+                                       $arr['verb'] = ACTIVITY_FRIEND;
+                                       $arr['object-type'] = ACTIVITY_OBJ_PERSON;
+                               
+                                       $A = '[url=' . $self[0]['url'] . ']' . $self[0]['name'] . '[/url]';
+                                       $B = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
+                                       $BPhoto = '[url=' . $contact['url'] . ']' . '[img]' . $contact['thumb'] . '[/img][/url]';
+                                       $arr['body'] =  sprintf( t('%1$s is now friends with %2$s'), $A, $B)."\n\n\n".$BPhoto;
+
+                                       $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $contact['name'] . '</title>'
+                                               . '<id>' . $contact['url'] . '/' . $contact['name'] . '</id>';
+                                       $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $contact['url'] . '" />' . "\n");
+                                       $arr['object'] .= xmlify('<link rel="photo" type="image/jpeg" href="' . $contact['thumb'] . '" />' . "\n");
+                                       $arr['object'] .= '</link></object>' . "\n";
+                                       $arr['last-child'] = 1;
+
+                                       $arr['allow_cid'] = $user[0]['allow_cid'];
+                                       $arr['allow_gid'] = $user[0]['allow_gid'];
+                                       $arr['deny_cid']  = $user[0]['deny_cid'];
+                                       $arr['deny_gid']  = $user[0]['deny_gid'];
+
+                                       $i = item_store($arr);
+                                       if($i)
+                                       proc_run('php',"include/notifier.php","activity","$i");
+                               }
+                       }
                }
                // Let's send our user to the contact editor in case they want to
                // do anything special with this new friend.
@@ -617,6 +632,15 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
                        xml_status(3,$message);
                }
 
+               // It's possible that the other person also requested friendship.
+               // If it is a duplex relationship, ditch the issued-id if one exists. 
+
+               if($duplex) {
+                       $r = q("UPDATE `contact` SET `issued-id` = '' WHERE `id` = %d LIMIT 1",
+                               intval($dfrn_record)
+                       );
+               }
+
                // We're good but now we have to scrape the profile photo and send notifications.