]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #1750 from annando/1507-contact-update
authorTobias Diekershoff <tobias.diekershoff@gmx.net>
Sun, 12 Jul 2015 13:32:29 +0000 (15:32 +0200)
committerTobias Diekershoff <tobias.diekershoff@gmx.net>
Sun, 12 Jul 2015 13:32:29 +0000 (15:32 +0200)
Automatic contact update

include/follow.php
include/onepoll.php
mod/receive.php
object/Item.php

index 287a38b6bffb03c33e81f5856da461661e3d6be0..6c998e1781118495242fcc1a67a6bb020601b8e1 100644 (file)
@@ -1,5 +1,48 @@
 <?php
+require_once("include/Scrape.php");
 
+function update_contact($id) {
+       /*
+       Warning: Never ever fetch the public key via probe_url and write it into the contacts.
+       This will reliably kill your communication with Friendica contacts.
+       */
+
+       $r = q("SELECT `url`, `nurl`, `addr`, `alias`, `batch`, `notify`, `poll`, `poco`, `network` FROM `contact` WHERE `id` = %d", intval($id));
+       if (!$r)
+               return;
+
+       $ret = probe_url($r[0]["url"]);
+
+       // If probe_url fails the network code will be different
+       if ($ret["network"] != $r[0]["network"])
+               return;
+
+       $update = false;
+
+       // make sure to not overwrite existing values with blank entries
+       foreach ($ret AS $key => $val) {
+               if (isset($r[0][$key]) AND ($r[0][$key] != "") AND ($val == ""))
+                       $ret[$key] = $r[0][$key];
+
+               if (isset($r[0][$key]) AND ($ret[$key] != $r[0][$key]))
+                       $update = true;
+       }
+
+       if (!$update)
+               return;
+
+       q("UPDATE `contact` SET `url` = '%s', `nurl` = '%s', `addr` = '%s', `alias` = '%s', `batch` = '%s', `notify` = '%s', `poll` = '%s', `poco` = '%s' WHERE `id` = %d",
+               dbesc($ret['url']),
+               dbesc(normalise_link($ret['url'])),
+               dbesc($ret['addr']),
+               dbesc($ret['alias']),
+               dbesc($ret['batch']),
+               dbesc($ret['notify']),
+               dbesc($ret['poll']),
+               dbesc($ret['poco']),
+               intval($id)
+       );
+}
 
 //
 // Takes a $uid and a url/handle and adds a new contact
@@ -120,9 +163,10 @@ function new_contact($uid,$url,$interactive = false) {
        // the poll url is more reliable than the profile url, as we may have
        // indirect links or webfinger links
 
-       $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `poll` = '%s' AND `network` = '%s' LIMIT 1",
+       $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `poll` IN ('%s', '%s') AND `network` = '%s' LIMIT 1",
                intval($uid),
                dbesc($ret['poll']),
+               dbesc(normalise_link($ret['poll'])),
                dbesc($ret['network'])
        );
 
@@ -136,8 +180,8 @@ function new_contact($uid,$url,$interactive = false) {
                                intval($uid)
                        );
                }
-       }
-       else {
+
+       else {
 
 
                // check service class limits
index 7b93a9a2f0d0a63e7ee422f0919b2b08c28597cf..d1f41d65f57e425808fe2d997f5b35c6560127c1 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 
 require_once("boot.php");
+require_once("include/follow.php");
 
 function RemoveReply($subject) {
        while (in_array(strtolower(substr($subject, 0, 3)), array("re:", "aw:")))
@@ -129,6 +130,10 @@ function onepoll_run(&$argv, &$argc){
                : datetime_convert('UTC','UTC',$contact['last-update'], ATOM_TIME)
        );
 
+       // Update the contact entry
+       if(($contact['network'] === NETWORK_OSTATUS) || ($contact['network'] === NETWORK_DIASPORA) || ($contact['network'] === NETWORK_DFRN))
+               update_contact($contact["id"]);
+
        if($contact['network'] === NETWORK_DFRN) {
 
 
@@ -243,8 +248,8 @@ function onepoll_run(&$argv, &$argc){
                        $final_dfrn_id = substr($final_dfrn_id,2);
 
                if($final_dfrn_id != $orig_id) {
-                       logger('poller: ID did not decode: ' . $contact['id'] . ' orig: ' . $orig_id . ' final: ' . $final_dfrn_id);    
-                       // did not decode properly - cannot trust this site 
+                       logger('poller: ID did not decode: ' . $contact['id'] . ' orig: ' . $orig_id . ' final: ' . $final_dfrn_id);
+                       // did not decode properly - cannot trust this site
                        return;
                }
 
@@ -255,7 +260,7 @@ function onepoll_run(&$argv, &$argc){
                $xml = post_url($contact['poll'],$postvars);
 
        }
-       elseif(($contact['network'] === NETWORK_OSTATUS) 
+       elseif(($contact['network'] === NETWORK_OSTATUS)
                || ($contact['network'] === NETWORK_DIASPORA)
                || ($contact['network'] === NETWORK_FEED) ) {
 
@@ -265,7 +270,8 @@ function onepoll_run(&$argv, &$argc){
 
                $stat_writeable = ((($contact['notify']) && ($contact['rel'] == CONTACT_IS_FOLLOWER || $contact['rel'] == CONTACT_IS_FRIEND)) ? 1 : 0);
 
-               if($contact['network'] === NETWORK_OSTATUS && get_pconfig($importer_uid,'system','ostatus_autofriend'))
+               // Contacts from OStatus are always writable
+               if($contact['network'] === NETWORK_OSTATUS)
                        $stat_writeable = 1;
 
                if($stat_writeable != $contact['writable']) {
index ee15ebe8a379936e52e9d9c7153da4b4170b26f7..95a51016757da46217f277e4b641799c43b1ec2c 100644 (file)
@@ -9,7 +9,7 @@ require_once('include/salmon.php');
 require_once('include/crypto.php');
 require_once('include/diaspora.php');
 
-       
+
 function receive_post(&$a) {
 
 
index 75f99742eb3e4ee41a661c6f43df4a4ba8335017..7f9762581c4268fddfae478fb280c013bcf4e92c 100644 (file)
@@ -308,7 +308,6 @@ class Item extends BaseObject {
                if (($item["item_network"] == NETWORK_FACEBOOK) AND ($indent == 'comment') AND isset($buttons["like"]))
                        unset($buttons["like"]);
 
-
                $tmp_item = array(
                        'template' => $this->get_template(),