]> git.mxchange.org Git - friendica.git/blobdiff - include/diaspora.php
nets widget - allow all children of specified parent net regardless of network
[friendica.git] / include / diaspora.php
index 7f1e4a8e33ab16f0d8bdc62407fb9275b33af358..5a19400daac04b494a2e8964954449617e9206db 100644 (file)
@@ -69,7 +69,7 @@ function diaspora_dispatch($importer,$msg) {
                $ret = diaspora_retraction($importer,$xmlbase->retraction,$msg);
        }
        elseif($xmlbase->signed_retraction) {
-               $ret = diaspora_signed_retraction($importer,$xmlbase->retraction,$msg);
+               $ret = diaspora_signed_retraction($importer,$xmlbase->signed_retraction,$msg);
        }
        elseif($xmlbase->photo) {
                $ret = diaspora_photo($importer,$xmlbase->photo,$msg);
@@ -188,6 +188,13 @@ function diaspora_msg_build($msg,$user,$contact,$prvkey,$pubkey,$public = false)
 
        logger('diaspora_msg_build: ' . $msg, LOGGER_DATA);
 
+       // without a public key nothing will work
+
+       if(! $pubkey) {
+               logger('diaspora_msg_build: pubkey missing: contact id: ' . $contact['id']);
+               return '';
+       }
+
        $inner_aes_key = random_string(32);
        $b_inner_aes_key = base64_encode($inner_aes_key);
        $inner_iv = random_string(16);
@@ -457,7 +464,7 @@ function diaspora_request($importer,$xml) {
                        intval($importer['uid'])
                );
 
-               if((count($r)) && ($r[0]['hide-friends'] == 0)) {
+               if((count($r)) && (! $r[0]['hide-friends']) && (! $contact['hidden'])) {
                        require_once('include/items.php');
 
                        $self = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
@@ -520,6 +527,8 @@ function diaspora_request($importer,$xml) {
 
        $batch = (($ret['batch']) ? $ret['batch'] : implode('/', array_slice(explode('/',$ret['url']),0,3)) . '/receive/public');
 
+
+
        $r = q("INSERT INTO `contact` (`uid`, `network`,`addr`,`created`,`url`,`nurl`,`batch`,`name`,`nick`,`photo`,`pubkey`,`notify`,`poll`,`blocked`,`priority`)
                VALUES ( %d, '%s', '%s', '%s', '%s','%s','%s','%s','%s','%s','%s','%s','%s',%d,%d) ",
                intval($importer['uid']),
@@ -543,9 +552,15 @@ function diaspora_request($importer,$xml) {
 
        $contact_record = diaspora_get_contact_by_handle($importer['uid'],$sender_handle);
 
-       $hash = random_string() . (string) time();   // Generate a confirm_key
+       if(! $contact_record) {
+               logger('diaspora_request: unable to locate newly created contact record.');
+               return;
+       }
+
+       if($importer['page-flags'] == PAGE_NORMAL) {
+
+               $hash = random_string() . (string) time();   // Generate a confirm_key
        
-       if($contact_record) {
                $ret = q("INSERT INTO `intro` ( `uid`, `contact-id`, `blocked`, `knowyou`, `note`, `hash`, `datetime` )
                        VALUES ( %d, %d, %d, %d, '%s', '%s', '%s' )",
                        intval($importer['uid']),
@@ -557,6 +572,49 @@ function diaspora_request($importer,$xml) {
                        dbesc(datetime_convert())
                );
        }
+       else {
+
+               // automatic friend approval
+
+               require_once('include/Photo.php');
+
+               $photos = import_profile_photo($contact_record['photo'],$importer['uid'],$contact_record['id']);
+               
+               // technically they are sharing with us (CONTACT_IS_SHARING), 
+               // but if our page-type is PAGE_COMMUNITY or PAGE_SOAPBOX
+               // we are going to change the relationship and make them a follower.
+
+               if($importer['page-flags'] == PAGE_FREELOVE)
+                       $new_relation = CONTACT_IS_FRIEND;
+               else
+                       $new_relation = CONTACT_IS_FOLLOWER;
+
+               $r = q("UPDATE `contact` SET 
+                       `photo` = '%s', 
+                       `thumb` = '%s',
+                       `micro` = '%s', 
+                       `rel` = %d, 
+                       `name-date` = '%s', 
+                       `uri-date` = '%s', 
+                       `avatar-date` = '%s', 
+                       `blocked` = 0, 
+                       `pending` = 0,
+                       WHERE `id` = %d LIMIT 1
+                       ",
+                       dbesc($photos[0]),
+                       dbesc($photos[1]),
+                       dbesc($photos[2]),
+                       intval($new_relation),
+                       dbesc(datetime_convert()),
+                       dbesc(datetime_convert()),
+                       dbesc(datetime_convert()),
+                       intval($contact_record['id'])
+               );
+
+               $u = q("select * from user where id = %d limit 1",intval($importer['uid']));
+               if($u)
+                       $ret = diaspora_share($u[0],$contact_record);
+       }
 
        return;
 }
@@ -1216,6 +1274,21 @@ function diaspora_conversation($importer,$xml,$msg) {
                        dbesc(datetime_convert()),
                        intval($conversation['id'])
                );              
+
+               require_once('include/enotify.php');
+               notification(array(                     
+                       'type' => NOTIFY_MAIL,
+                       'notify_flags' => $importer['notify-flags'],
+                       'language' => $importer['language'],
+                       'to_name' => $importer['username'],
+                       'to_email' => $importer['email'],
+                       'item' => array('subject' => $subject, 'body' => $body),
+                       'source_name' => $person['name'],
+                       'source_link' => $person['url'],
+                       'source_photo' => $person['thumb'],
+                       'verb' => ACTIVITY_POST,
+                       'otype' => 'mail'
+               ));
        }       
 
        return;
@@ -1562,6 +1635,7 @@ EOT;
 
 function diaspora_retraction($importer,$xml) {
 
+
        $guid = notags(unxmlify($xml->guid));
        $diaspora_handle = notags(unxmlify($xml->diaspora_handle));
        $type = notags(unxmlify($xml->type));
@@ -1593,7 +1667,8 @@ function diaspora_retraction($importer,$xml) {
        // NOTREACHED
 }
 
-function diaspora_signed_retraction($importer,$xml) {
+function diaspora_signed_retraction($importer,$xml,$msg) {
+
 
        $guid = notags(unxmlify($xml->target_guid));
        $diaspora_handle = notags(unxmlify($xml->sender_handle));
@@ -1601,8 +1676,10 @@ function diaspora_signed_retraction($importer,$xml) {
        $sig = notags(unxmlify($xml->target_author_signature));
 
        $contact = diaspora_get_contact_by_handle($importer['uid'],$diaspora_handle);
-       if(! $contact)
+       if(! $contact) {
+               logger('diaspora_signed_retraction: no contact');
                return;
+       }
 
        // this may not yet work for comments. Need to see how the relaying works
        // and figure out who signs it.
@@ -1621,7 +1698,7 @@ function diaspora_signed_retraction($importer,$xml) {
 
        if($type === 'StatusMessage') {
                $r = q("select * from item where guid = '%s' and uid = %d limit 1",
-                       dbesc('guid'),
+                       dbesc($guid),
                        intval($importer['uid'])
                );
                if(count($r)) {
@@ -1633,6 +1710,8 @@ function diaspora_signed_retraction($importer,$xml) {
                        }
                }
        }
+       else
+               logger('diaspora_signed_retraction: unknown type: ' . $type);
 
        return 202;
        // NOTREACHED
@@ -1672,6 +1751,12 @@ function diaspora_profile($importer,$xml) {
 
        $birthday = datetime_convert('UTC','UTC',$birthday,'Y-m-d');
 
+       // this is to prevent multiple birthday notifications in a single year
+       // if we already have a stored birthday and the 'm-d' part hasn't changed, preserve the entry, which will preserve the notify year
+
+       if(substr($birthday,5) === substr($contact['bd'],5))
+               $birthday = $contact['bd'];
+
        $r = q("UPDATE `contact` SET `name` = '%s', `name-date` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' , `bd` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1",
                dbesc($name),
                dbesc(datetime_convert()),
@@ -1700,27 +1785,6 @@ function diaspora_profile($importer,$xml) {
 
 }
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
 function diaspora_share($me,$contact) {
        $a = get_app();
        $myaddr = $me['nickname'] . '@' .  substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);