]> git.mxchange.org Git - friendica.git/blobdiff - include/follow.php
Merge pull request #3786 from tobiasd/3.5.4-CHANGELOG
[friendica.git] / include / follow.php
index 48e23bff627dc6341b628e4b0afccc84dce6d74c..c5214fe4612ae22bb24e16338e8726af035c5aa2 100644 (file)
@@ -2,6 +2,7 @@
 
 use Friendica\App;
 use Friendica\Core\System;
+use Friendica\Network\Probe;
 
 require_once 'include/probe.php';
 require_once 'include/socgraph.php';
@@ -71,7 +72,7 @@ function update_contact($id) {
 
 
 
-function new_contact($uid,$url,$interactive = false) {
+function new_contact($uid, $url, $interactive = false, $network = '') {
 
        $result = array('cid' => -1, 'success' => false,'message' => '');
 
@@ -102,9 +103,13 @@ function new_contact($uid,$url,$interactive = false) {
 
        if (x($arr['contact'],'name')) {
                $ret = $arr['contact'];
+       } else {
+               $ret = Probe::uri($url, $network, $uid, false);
        }
-       else {
-               $ret = probe_url($url);
+
+       if (($network != '') && ($ret['network'] != $network)) {
+               logger('Expected network '.$network.' does not match actual network '.$ret['network']);
+               return result;
        }
 
        if ($ret['network'] === NETWORK_DFRN) {
@@ -187,14 +192,10 @@ function new_contact($uid,$url,$interactive = false) {
 
        if (dbm::is_result($r)) {
                // update contact
-               if ($r[0]['rel'] == CONTACT_IS_FOLLOWER || ($network === NETWORK_DIASPORA && $r[0]['rel'] == CONTACT_IS_SHARING)) {
-                       q("UPDATE `contact` SET `rel` = %d , `subhub` = %d, `readonly` = 0 WHERE `id` = %d AND `uid` = %d",
-                               intval(CONTACT_IS_FRIEND),
-                               intval($subhub),
-                               intval($r[0]['id']),
-                               intval($uid)
-                       );
-               }
+               $new_relation = (($r[0]['rel'] == CONTACT_IS_FOLLOWER) ? CONTACT_IS_FRIEND : CONTACT_IS_SHARING);
+
+               $fields = array('rel' => $new_relation, 'subhub' => $subhub, 'readonly' => false);
+               dba::update('contact', $fields, array('id' => $r[0]['id']));
        } else {
                // check service class limits
 
@@ -222,7 +223,7 @@ function new_contact($uid,$url,$interactive = false) {
                        return $result;
                }
 
-               $new_relation = ((in_array($ret['network'], array(NETWORK_MAIL, NETWORK_DIASPORA))) ? CONTACT_IS_FRIEND : CONTACT_IS_SHARING);
+               $new_relation = ((in_array($ret['network'], array(NETWORK_MAIL))) ? CONTACT_IS_FRIEND : CONTACT_IS_SHARING);
 
                // create contact record
                $r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `nurl`, `addr`, `alias`, `batch`, `notify`, `poll`, `poco`, `name`, `nick`, `network`, `pubkey`, `rel`, `priority`,