X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Fdfrn_confirm.php;h=0bc3ea7df597550f96286b8210fc6925da788876;hb=4690d00141352db8ca96359cbbf65ce6eb4345c4;hp=24e8bf106a9a938dcf6e0ddf3352b2839fcbf38f;hpb=e9251499dd63523a552bc3bf6274e3b851cba4c8;p=friendica.git
diff --git a/mod/dfrn_confirm.php b/mod/dfrn_confirm.php
index 24e8bf106a..0bc3ea7df5 100644
--- a/mod/dfrn_confirm.php
+++ b/mod/dfrn_confirm.php
@@ -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,10 +127,13 @@ 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);
- $network = ((strlen($contact['issued-id'])) ? 'dfrn' : 'stat');
+ if($contact['network'])
+ $network = $contact['network'];
- if($network === 'dfrn') {
+ if($network === NETWORK_DFRN) {
/**
*
@@ -240,12 +248,12 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
notice( t('Unexpected response from remote site: ') . EOL . $leading_junk . EOL );
}
- $xml = simplexml_load_string($res);
+ $xml = parse_xml_string($res);
$status = (int) $xml->status;
$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;
@@ -298,22 +306,23 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
*
*/
- require_once("Photo.php");
+ require_once('include/Photo.php');
$photos = import_profile_photo($contact['photo'],$uid,$contact_id);
logger('dfrn_confirm: confirm - imported photos');
- if($network === 'dfrn') {
+ if($network === NETWORK_DFRN) {
- $new_relation = REL_VIP;
- if(($relation == REL_FAN) || ($duplex))
- $new_relation = REL_BUD;
+ $new_relation = CONTACT_IS_FOLLOWER;
+ if(($relation == CONTACT_IS_SHARING) || ($duplex))
+ $new_relation = CONTACT_IS_FRIEND;
- if(($relation == REL_FAN) && ($duplex))
+ 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,
@@ -323,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]),
@@ -333,25 +343,43 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
dbesc(datetime_convert()),
dbesc(datetime_convert()),
intval($duplex),
+ intval($hidden),
intval($contact_id)
);
}
else {
- // $network !== 'dfrn'
-
- $notify = '';
- $poll = '';
-
- $arr = lrdd($contact['url']);
- if(count($arr)) {
- foreach($arr as $link) {
- if($link['@attributes']['rel'] === 'salmon')
- $notify = $link['@attributes']['href'];
- if($link['@attributes']['rel'] === NAMESPACE_FEED)
- $poll = $link['@attributes']['href'];
+
+ // $network !== NETWORK_DFRN
+
+ $network = (($contact['network']) ? $contact['network'] : NETWORK_OSTATUS);
+ $notify = (($contact['notify']) ? $contact['notify'] : '');
+ $poll = (($contact['poll']) ? $contact['poll'] : '');
+
+ if((! $contact['notify']) || (! $contact['poll'])) {
+ $arr = lrdd($contact['url']);
+ if(count($arr)) {
+ foreach($arr as $link) {
+ if($link['@attributes']['rel'] === 'salmon')
+ $notify = $link['@attributes']['href'];
+ if($link['@attributes']['rel'] === NAMESPACE_FEED)
+ $poll = $link['@attributes']['href'];
+ }
}
}
+ $new_relation = $contact['rel'];
+ $writable = $contact['writable'];
+
+ 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;
+ }
+
$r = q("DELETE FROM `intro` WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($intro_id),
intval($uid)
@@ -368,7 +396,10 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
`poll` = '%s',
`blocked` = 0,
`pending` = 0,
- `network` = 'stat'
+ `network` = '%s',
+ `writable` = %d,
+ `hidden` = %d,
+ `rel` = %d
WHERE `id` = %d LIMIT 1
",
dbesc($photos[0]),
@@ -379,6 +410,10 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
dbesc(datetime_convert()),
dbesc($notify),
dbesc($poll),
+ dbesc($network),
+ intval($writable),
+ intval($hidden),
+ intval($new_relation),
intval($contact_id)
);
}
@@ -396,53 +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 == REL_BUD)) {
+ 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;
- $arr['body'] = '[url=' . $self[0]['url'] . ']' . $self[0]['name'] . '[/url] ' . t('is now friends with')
- . ' [url=' . $contact['url'] . ']' . $contact['name'] . '[/url]' . "\n\n\n"
- . ' [url=' . $contact['url'] . ']' . '[img]' . $contact['thumb'] . '[/img][/url]';
-
- $arr['object'] = '' . "\n";
- $arr['last-child'] = 1;
-
- $i = item_store($arr);
-
- $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
-
- //proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"activity\" \"$i\" &", array(),$foo));
- proc_run($php_path,"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'] = '' . "\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.
@@ -494,7 +541,7 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
dbesc($node));
if(! count($r)) {
- $message = t('No user record found for ') . '\'' . $node . '\'';
+ $message = sprintf(t('No user record found for \'%s\' '), $node);
xml_status(3,$message); // failure
// NOTREACHED
}
@@ -503,7 +550,7 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
$local_uid = $r[0]['uid'];
- if(! strstr($my_prvkey,'BEGIN RSA PRIVATE KEY')) {
+ if(! strstr($my_prvkey,'PRIVATE KEY')) {
$message = t('Our site encryption key is apparently messed up.');
xml_status(3,$message);
}
@@ -524,12 +571,22 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
dbesc($decrypted_source_url),
intval($local_uid)
);
-
if(! count($ret)) {
- // this is either a bogus confirmation (?) or we deleted the original introduction.
- $message = t('Contact record was not found for you on our site.');
- xml_status(3,$message);
- return; // NOTREACHED
+ if(strstr($decrypted_source_url,'http:'))
+ $newurl = str_replace('http:','https:',$decrypted_source_url);
+ else
+ $newurl = str_replace('https:','http:',$decrypted_source_url);
+
+ $ret = q("SELECT * FROM `contact` WHERE `url` = '%s' AND `uid` = %d LIMIT 1",
+ dbesc($newurl),
+ intval($local_uid)
+ );
+ if(! count($ret)) {
+ // this is either a bogus confirmation (?) or we deleted the original introduction.
+ $message = t('Contact record was not found for you on our site.');
+ xml_status(3,$message);
+ return; // NOTREACHED
+ }
}
$relation = $ret[0]['rel'];
@@ -539,6 +596,11 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
$foreign_pubkey = $ret[0]['site-pubkey'];
$dfrn_record = $ret[0]['id'];
+ if(! $foreign_pubkey) {
+ $message = sprintf( t('Site public key not available in contact record for URL %s.'), $newurl);
+ xml_status(3,$message);
+ }
+
$decrypted_dfrn_id = "";
openssl_public_decrypt($dfrn_id,$decrypted_dfrn_id,$foreign_pubkey);
@@ -570,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.
@@ -588,11 +659,11 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
logger('dfrn_confirm: request - photos imported');
- $new_relation = REL_FAN;
- if(($relation == REL_VIP) || ($duplex))
- $new_relation = REL_BUD;
+ $new_relation = CONTACT_IS_SHARING;
+ if(($relation == CONTACT_IS_FOLLOWER) || ($duplex))
+ $new_relation = CONTACT_IS_FRIEND;
- if(($relation == REL_VIP) && ($duplex))
+ if(($relation == CONTACT_IS_FOLLOWER) && ($duplex))
$duplex = 0;
$r = q("UPDATE `contact` SET
@@ -606,7 +677,7 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
`blocked` = 0,
`pending` = 0,
`duplex` = %d,
- `network` = 'dfrn' WHERE `id` = %d LIMIT 1
+ `network` = '%s' WHERE `id` = %d LIMIT 1
",
dbesc($photos[0]),
dbesc($photos[1]),
@@ -616,6 +687,7 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
dbesc(datetime_convert()),
dbesc(datetime_convert()),
intval($duplex),
+ dbesc(NETWORK_DFRN),
intval($dfrn_record)
);
if($r === false) { // indicates schema is messed up or total db failure
@@ -628,15 +700,16 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
logger('dfrn_confirm: request: info updated');
- $r = q("SELECT * FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
+ $r = q("SELECT `contact`.*, `user`.* FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
WHERE `contact`.`id` = %d LIMIT 1",
intval($dfrn_record)
);
if((count($r)) && ($r[0]['notify-flags'] & NOTIFY_CONFIRM)) {
- $tpl = (($new_relation == REL_BUD)
- ? load_view_file('view/friend_complete_eml.tpl')
- : load_view_file('view/intro_complete_eml.tpl'));
+ push_lang($r[0]['language']);
+ $tpl = (($new_relation == CONTACT_IS_FRIEND)
+ ? get_intltext_template('friend_complete_eml.tpl')
+ : get_intltext_template('intro_complete_eml.tpl'));
$email_tpl = replace_macros($tpl, array(
'$sitename' => $a->config['sitename'],
@@ -648,11 +721,16 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
'$uid' => $newuid )
);
- $res = mail($r[0]['email'], t("Connection accepted at ") . $a->config['sitename'],
- $email_tpl, 'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME'] );
+ $res = mail($r[0]['email'], sprintf( t("Connection accepted at %s") , $a->config['sitename']),
+ $email_tpl,
+ 'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME'] . "\n"
+ . 'Content-type: text/plain; charset=UTF-8' . "\n"
+ . 'Content-transfer-encoding: 8bit' );
+
if(!$res) {
// pointless throwing an error here and confusing the person at the other end of the wire.
}
+ pop_lang();
}
xml_status(0); // Success
return; // NOTREACHED
@@ -662,7 +740,7 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
// somebody arrived here by mistake or they are fishing. Send them to the homepage.
- goaway($a->get_baseurl());
+ goaway(z_root());
// NOTREACHED
}