X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Ffollow.php;h=83806ade7ee16406e7a110c1a5c5250d9076a6cb;hb=478e363967165980eb826e8d109dd15770e2c784;hp=8d80538e0c924856c51c0547511d4e4769f750aa;hpb=370571845b989babab5eb15d1a3f1b8ddf5ddf57;p=friendica.git diff --git a/include/follow.php b/include/follow.php index 8d80538e0c..83806ade7e 100644 --- a/include/follow.php +++ b/include/follow.php @@ -1,11 +1,17 @@ $val) { - if (isset($r[0][$key]) AND ($r[0][$key] != "") AND ($val == "")) + if (isset($r[0][$key]) && ($r[0][$key] != "") && ($val == "")) $ret[$key] = $r[0][$key]; - if (isset($r[0][$key]) AND ($ret[$key] != $r[0][$key])) + if (isset($r[0][$key]) && ($ret[$key] != $r[0][$key])) $update = true; } @@ -67,7 +73,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' => ''); @@ -82,6 +88,11 @@ function new_contact($uid,$url,$interactive = false) { return $result; } + if (blocked_url($url)) { + $result['message'] = t('Blocked domain'); + return $result; + } + if (! $url) { $result['message'] = t('Connect URL missing.'); return $result; @@ -93,15 +104,19 @@ 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) { if ($interactive) { if (strlen($a->path)) { - $myaddr = bin2hex(App::get_baseurl() . '/profile/' . $a->user['nickname']); + $myaddr = bin2hex(System::baseUrl() . '/profile/' . $a->user['nickname']); } else { $myaddr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname()); } @@ -110,12 +125,10 @@ function new_contact($uid,$url,$interactive = false) { // NOTREACHED } - } else { - if (get_config('system','dfrn_only')) { - $result['message'] = t('This site is not configured to allow communications with other networks.') . EOL; - $result['message'] != t('No compatible communication protocols or feeds were discovered.') . EOL; - return $result; - } + } elseif (get_config('system','dfrn_only')) { + $result['message'] = t('This site is not configured to allow communications with other networks.') . EOL; + $result['message'] != t('No compatible communication protocols or feeds were discovered.') . EOL; + return $result; } // This extra param just confuses things, remove it @@ -180,42 +193,12 @@ 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) - ); - } - } else { - // check service class limits + $new_relation = (($r[0]['rel'] == CONTACT_IS_FOLLOWER) ? CONTACT_IS_FRIEND : CONTACT_IS_SHARING); - $r = q("SELECT COUNT(*) AS `total` FROM `contact` WHERE `uid` = %d AND `pending` = 0 AND `self` = 0", - intval($uid) - ); - if (dbm::is_result($r)) - $total_contacts = $r[0]['total']; - - if (! service_class_allows($uid,'total_contacts',$total_contacts)) { - $result['message'] .= upgrade_message(); - return $result; - } - - $r = q("SELECT COUNT(`network`) AS `total` FROM `contact` WHERE `uid` = %d AND `network` = '%s' AND `pending` = 0 AND `self` = 0", - intval($uid), - dbesc($network) - ); - if (dbm::is_result($r)) { - $total_network = $r[0]['total']; - } - - if (! service_class_allows($uid,'total_contacts_' . $network,$total_network)) { - $result['message'] .= upgrade_message(); - return $result; - } - - $new_relation = ((in_array($ret['network'], array(NETWORK_MAIL, NETWORK_DIASPORA))) ? 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 { + $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`, @@ -268,7 +251,7 @@ function new_contact($uid,$url,$interactive = false) { // pull feed and consume it, which should subscribe to the hub. - proc_run(PRIORITY_HIGH, "include/onepoll.php", $contact_id, "force"); + Worker::add(PRIORITY_HIGH, "onepoll", $contact_id, "force"); $r = q("SELECT `contact`.*, `user`.* FROM `contact` INNER JOIN `user` ON `contact`.`uid` = `user`.`uid` WHERE `user`.`uid` = %d AND `contact`.`self` LIMIT 1",