]> git.mxchange.org Git - friendica.git/blobdiff - mod/dfrn_confirm.php
report failure to generate keys
[friendica.git] / mod / dfrn_confirm.php
index cc1edea229baee150eb6dca2aa82c2b5b6491837..13353a3641c1424acb90f64c5840092b6a2c3e6b 100644 (file)
@@ -2,6 +2,7 @@
 
 // There are two possible entry points. 
 
+
 function dfrn_confirm_post(&$a,$handsfree = null) {
 
        if(is_array($handsfree)) {
@@ -48,6 +49,7 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
                        $dfrn_id = $handsfree['dfrn_id'];
                        $intro_id = $handsfree['intro_id'];
                        $duplex = $handsfree['duplex'];
+                       logger('dfrn_confirm: Confirm in handsfree mode');
                }
                else {
                        $dfrn_id  = ((x($_POST,'dfrn_id')) ? notags(trim($_POST['dfrn_id'])) : "");
@@ -56,6 +58,9 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
                        $cid      = intval($_POST['contact_id']);
                }
 
+               logger('dfrn_confirm: Confirming request for dfrn_id (issued) ' . $dfrn_id);
+
+
                // The other person will have been issued an ID when they first requested friendship.
                // Locate their record. At this time, their record will have both pending and blocked set to 1. 
                // There won't be any dfrn_id if this is a network follower, so use the contact_id instead.
@@ -79,8 +84,9 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
                $dfrn_confirm = $contact['confirm'];
                $aes_allow    = $contact['aes_allow'];
 
+               $network = ((strlen($contact['issued-id'])) ? 'dfrn' : 'stat');
 
-               if($contact['network'] === 'dfrn') {
+               if($network === 'dfrn') {
 
                        // Generate a key pair for all further communications with this person.
                        // We have a keypair for every contact, and a site key for unknown people.
@@ -147,10 +153,14 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
                        if($duplex == 1)
                                $params['duplex'] = 1;
 
+                       logger('dfrn_confirm: Confirm: posted data: ' . print_r($params,true), LOGGER_DATA);
+
                        // POST all this stuff to the other site.
 
                        $res = post_url($dfrn_confirm,$params);
 
+                       logger('dfrn_confirm: Confirm: received data: ' . $res, LOGGER_DATA);
+
                        // Now figure out what they responded. Try to be robust if the remote site is 
                        // having difficulty and throwing up errors of some kind. 
 
@@ -229,49 +239,22 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
 
                require_once("Photo.php");
 
-               $photo_failure = false;
-
-               $filename = basename($contact['photo']);
-               $img_str = fetch_url($contact['photo'],true);
-               $img = new Photo($img_str);
-               if($img->is_valid()) {
-
-                       $img->scaleImageSquare(175);
-                                       
-                       $hash = photo_new_resource();
-
-                       $r = $img->store($uid, $contact_id, $hash, $filename, t('Contact Photos'), 4 );
-
-                       if($r === false)
-                               $photo_failure = true;
-
-                       $img->scaleImage(80);
-
-                       $r = $img->store($uid, $contact_id, $hash, $filename, t('Contact Photos'), 5 );
-
-                       if($r === false)
-                               $photo_failure = true;
-
-                       $photo = $a->get_baseurl() . '/photo/' . $hash . '-4.jpg';
-                       $thumb = $a->get_baseurl() . '/photo/' . $hash . '-5.jpg';
-               }
-               else
-                       $photo_failure = true;
-
-               if($photo_failure) {
-                       $photo = $a->get_baseurl() . '/images/default-profile.jpg';
-                       $thumb = $a->get_baseurl() . '/images/default-profile-sm.jpg';
-               }
-
+               $photos = import_profile_photo($contact['photo'],$uid,$contact_id);
+               
+               logger('dfrn_confirm: confirm - imported photos');
 
-               if($contact['network'] === 'dfrn') {
+               if($network === 'dfrn') {
 
                        $new_relation = REL_VIP;
                        if(($relation == REL_FAN) || ($duplex))
                                $new_relation = REL_BUD;
 
+                       if(($relation == REL_FAN) && ($duplex))
+                               $duplex = 0;
+
                        $r = q("UPDATE `contact` SET `photo` = '%s', 
-                               `thumb` = '%s', 
+                               `thumb` = '%s',
+                               `micro` = '%s', 
                                `rel` = %d, 
                                `name-date` = '%s', 
                                `uri-date` = '%s', 
@@ -281,8 +264,9 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
                                `duplex` = %d,
                                `network` = 'dfrn' WHERE `id` = %d LIMIT 1
                        ",
-                               dbesc($photo),
-                               dbesc($thumb),
+                               dbesc($photos[0]),
+                               dbesc($photos[1]),
+                               dbesc($photos[2]),
                                intval($new_relation),
                                dbesc(datetime_convert()),
                                dbesc(datetime_convert()),
@@ -296,7 +280,7 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
                        $notify = '';
                        $poll   = '';
 
-                       // $contact['network'] !== 'dfrn'
+                       // $network !== 'dfrn'
 
                        $arr = lrdd($contact['url']);
                        if(count($arr)) {
@@ -313,19 +297,23 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
                                intval($uid)
                        );
 
+
                        $r = q("UPDATE `contact` SET `photo` = '%s', 
-                               `thumb` = '%s', 
+                               `thumb` = '%s',
+                               `micro` = '%s', 
                                `name-date` = '%s', 
                                `uri-date` = '%s', 
                                `avatar-date` = '%s', 
                                `notify` = '%s',
                                `poll` = '%s',
                                `blocked` = 0, 
-                               `pending` = 0
+                               `pending` = 0,
+                               `network` = 'stat'
                                WHERE `id` = %d LIMIT 1
                        ",
-                               dbesc($photo),
-                               dbesc($thumb),
+                               dbesc($photos[0]),
+                               dbesc($photos[1]),
+                               dbesc($photos[2]),
                                dbesc(datetime_convert()),
                                dbesc(datetime_convert()),
                                dbesc(datetime_convert()),
@@ -369,7 +357,10 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
                $aes_key    = $_POST['aes_key'];
                $duplex     = $_POST['duplex'];
                $version_id = (float) $_POST['dfrn_version'];
+       
+               logger('dfrn_confirm: requestee contacted: ' . $node);
 
+               logger('dfrn_confirm: request: POST=' . print_r($_POST,true), LOGGER_DATA);
 
                // If $aes_key is set, both of these items require unpacking from the hex transport encoding.
 
@@ -442,8 +433,7 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
                }
 
                $r = q("SELECT * FROM `contact` WHERE `dfrn-id` = '%s' LIMIT 1",
-                       dbesc($decrypted_dfrn_id),
-                       intval($local_uid)
+                       dbesc($decrypted_dfrn_id)
                );
                if(count($r)) {
                        $message = t('The ID provided by your system is a duplicate on our system. It should work if you try again.');
@@ -463,55 +453,33 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
 
                // We're good but now we have to scrape the profile photo and send notifications.
 
-               require_once("Photo.php");
 
-               $photo_failure = false;
 
                $r = q("SELECT `photo` FROM `contact` WHERE `id` = %d LIMIT 1",
                        intval($dfrn_record));
-               if(count($r)) {
-
-                       $filename = basename($r[0]['photo']);
-                       $img_str = fetch_url($r[0]['photo'],true);
-                       $img = new Photo($img_str);
-                       if($img->is_valid()) {
-
-                               $img->scaleImageSquare(175);
-                                       
-                               $hash = photo_new_resource();
-
-                               $r = $img->store($local_uid, $dfrn_record, $hash, $filename, t('Contact Photos') , 4);
-
-                               if($r === false)
-                                       $photo_failure = true;
-                                       
-                               $img->scaleImage(80);
-                               $r = $img->store($local_uid, $dfrn_record, $hash, $filename, t('Contact Photos') , 5);
-
-                               if($r === false)
-                                       $photo_failure = true;
 
-                               $photo = $a->get_baseurl() . '/photo/' . $hash . '-4.jpg';
-                               $thumb = $a->get_baseurl() . '/photo/' . $hash . '-5.jpg';      
-                       }
-                       else
-                               $photo_failure = true;
-               }
+               if(count($r))
+                       $photo = $r[0]['photo'];
                else
-                       $photo_failure = true;
-
-               if($photo_failure) {
                        $photo = $a->get_baseurl() . '/images/default-profile.jpg';
-                       $thumb = $a->get_baseurl() . '/images/default-profile-sm.jpg';
-               }
+                               
+               require_once("Photo.php");
+
+               $photos = import_profile_photo($photo,$local_uid,$dfrn_record);
+
+               logger('dfrn_confirm: request - photos imported');
 
                $new_relation = REL_FAN;
                if(($relation == REL_VIP) || ($duplex))
                        $new_relation = REL_BUD;
 
+               if(($relation == REL_VIP) && ($duplex))
+                       $duplex = 0;
+
                $r = q("UPDATE `contact` SET 
                        `photo` = '%s', 
                        `thumb` = '%s', 
+                       `micro` = '%s',
                        `rel` = %d, 
                        `name-date` = '%s', 
                        `uri-date` = '%s', 
@@ -521,8 +489,9 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
                        `duplex` = %d, 
                        `network` = 'dfrn' WHERE `id` = %d LIMIT 1
                ",
-                       dbesc($photo),
-                       dbesc($thumb),
+                       dbesc($photos[0]),
+                       dbesc($photos[1]),
+                       dbesc($photos[2]),
                        intval($new_relation),
                        dbesc(datetime_convert()),
                        dbesc(datetime_convert()),
@@ -538,6 +507,8 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
                // Otherwise everything seems to have worked and we are almost done. Yay!
                // Send an email notification
 
+               logger('dfrn_confirm: request: info updated');
+
                $r = q("SELECT * FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
                        WHERE `contact`.`id` = %d LIMIT 1",
                        intval($dfrn_record)
@@ -559,7 +530,7 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
                        );
        
                        $res = mail($r[0]['email'], t("Connection accepted at ") . $a->config['sitename'],
-                               $email_tpl, 'From: ' . t('Administrator') . '@' . $_SERVER[SERVER_NAME] );
+                               $email_tpl, 'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME'] );
                        if(!$res) {
                                // pointless throwing an error here and confusing the person at the other end of the wire.
                        }