]> git.mxchange.org Git - friendica.git/blobdiff - include/dfrn.php
Merge pull request #2758 from annando/1609-sql-charset
[friendica.git] / include / dfrn.php
index 2dca1522c62da7b10af55c49c47de5c44111f7fd..27fc644c6b21d2dbbf99d6b17f36c43cb1dfaa52 100644 (file)
@@ -368,6 +368,8 @@ class dfrn {
 
                xml::add_element($doc, $relocate, "dfrn:url", $owner['url']);
                xml::add_element($doc, $relocate, "dfrn:name", $owner['name']);
+               xml::add_element($doc, $relocate, "dfrn:addr", $owner['addr']);
+               xml::add_element($doc, $relocate, "dfrn:avatar", $owner['avatar']);
                xml::add_element($doc, $relocate, "dfrn:photo", $photos[4]);
                xml::add_element($doc, $relocate, "dfrn:thumb", $photos[5]);
                xml::add_element($doc, $relocate, "dfrn:micro", $photos[6]);
@@ -1545,7 +1547,9 @@ class dfrn {
                $relocate["uid"] = $importer["importer_uid"];
                $relocate["cid"] = $importer["id"];
                $relocate["url"] = $xpath->query("dfrn:url/text()", $relocation)->item(0)->nodeValue;
+               $relocate["addr"] = $xpath->query("dfrn:addr/text()", $relocation)->item(0)->nodeValue;
                $relocate["name"] = $xpath->query("dfrn:name/text()", $relocation)->item(0)->nodeValue;
+               $relocate["avatar"] = $xpath->query("dfrn:avatar/text()", $relocation)->item(0)->nodeValue;
                $relocate["photo"] = $xpath->query("dfrn:photo/text()", $relocation)->item(0)->nodeValue;
                $relocate["thumb"] = $xpath->query("dfrn:thumb/text()", $relocation)->item(0)->nodeValue;
                $relocate["micro"] = $xpath->query("dfrn:micro/text()", $relocation)->item(0)->nodeValue;
@@ -1555,6 +1559,12 @@ class dfrn {
                $relocate["poll"] = $xpath->query("dfrn:poll/text()", $relocation)->item(0)->nodeValue;
                $relocate["sitepubkey"] = $xpath->query("dfrn:sitepubkey/text()", $relocation)->item(0)->nodeValue;
 
+               if (($relocate["avatar"] == "") AND ($relocate["photo"] != ""))
+                       $relocate["avatar"] = $relocate["photo"];
+
+               if ($relocate["addr"] == "")
+                       $relocate["addr"] = preg_replace("=(https?://)(.*)/profile/(.*)=ism", "$3@$2", $relocate["url"]);
+
                // update contact
                $r = q("SELECT `photo`, `url` FROM `contact` WHERE `id` = %d AND `uid` = %d;",
                        intval($importer["id"]),
@@ -1564,51 +1574,83 @@ class dfrn {
 
                $old = $r[0];
 
-               $x = q("UPDATE `contact` SET
+               // Update the gcontact entry
+               $relocate["server_url"] = preg_replace("=(https?://)(.*)/profile/(.*)=ism", "$1$2", $relocate["url"]);
+
+               $x = q("UPDATE `gcontact` SET
                                        `name` = '%s',
                                        `photo` = '%s',
-                                       `thumb` = '%s',
-                                       `micro` = '%s',
                                        `url` = '%s',
                                        `nurl` = '%s',
+                                       `addr` = '%s',
+                                       `connect` = '%s',
+                                       `notify` = '%s',
+                                       `server_url` = '%s'
+                       WHERE `nurl` = '%s';",
+                                       dbesc($relocate["name"]),
+                                       dbesc($relocate["avatar"]),
+                                       dbesc($relocate["url"]),
+                                       dbesc(normalise_link($relocate["url"])),
+                                       dbesc($relocate["addr"]),
+                                       dbesc($relocate["addr"]),
+                                       dbesc($relocate["notify"]),
+                                       dbesc($relocate["server_url"]),
+                                       dbesc(normalise_link($old["url"])));
+
+               // Update the contact table. We try to find every entry.
+               $x = q("UPDATE `contact` SET
+                                       `name` = '%s',
+                                       `avatar` = '%s',
+                                       `url` = '%s',
+                                       `nurl` = '%s',
+                                       `addr` = '%s',
                                        `request` = '%s',
                                        `confirm` = '%s',
                                        `notify` = '%s',
                                        `poll` = '%s',
                                        `site-pubkey` = '%s'
-                       WHERE `id` = %d AND `uid` = %d;",
+                       WHERE (`id` = %d AND `uid` = %d) OR (`nurl` = '%s');",
                                        dbesc($relocate["name"]),
-                                       dbesc($relocate["photo"]),
-                                       dbesc($relocate["thumb"]),
-                                       dbesc($relocate["micro"]),
+                                       dbesc($relocate["avatar"]),
                                        dbesc($relocate["url"]),
                                        dbesc(normalise_link($relocate["url"])),
+                                       dbesc($relocate["addr"]),
                                        dbesc($relocate["request"]),
                                        dbesc($relocate["confirm"]),
                                        dbesc($relocate["notify"]),
                                        dbesc($relocate["poll"]),
                                        dbesc($relocate["sitepubkey"]),
                                        intval($importer["id"]),
-                                       intval($importer["importer_uid"]));
+                                       intval($importer["importer_uid"]),
+                                       dbesc(normalise_link($old["url"])));
+
+               update_contact_avatar($relocate["avatar"], $importer["importer_uid"], $importer["id"], true);
 
                if ($x === false)
                        return false;
 
                // update items
+               /// @todo This is an extreme performance killer
                $fields = array(
                        'owner-link' => array($old["url"], $relocate["url"]),
                        'author-link' => array($old["url"], $relocate["url"]),
-                       'owner-avatar' => array($old["photo"], $relocate["photo"]),
-                       'author-avatar' => array($old["photo"], $relocate["photo"]),
+                       //'owner-avatar' => array($old["photo"], $relocate["photo"]),
+                       //'author-avatar' => array($old["photo"], $relocate["photo"]),
                        );
-               foreach ($fields as $n=>$f){
-                       $x = q("UPDATE `item` SET `%s` = '%s' WHERE `%s` = '%s' AND `uid` = %d",
-                                       $n, dbesc($f[1]),
+               foreach ($fields as $n=>$f) {
+                       $r = q("SELECT `id` FROM `item` WHERE `%s` = '%s' AND `uid` = %d LIMIT 1",
                                        $n, dbesc($f[0]),
                                        intval($importer["importer_uid"]));
-                               if ($x === false)
-                                       return false;
+
+                       if ($r) {
+                               $x = q("UPDATE `item` SET `%s` = '%s' WHERE `%s` = '%s' AND `uid` = %d",
+                                               $n, dbesc($f[1]),
+                                               $n, dbesc($f[0]),
+                                               intval($importer["importer_uid"]));
+                                       if ($x === false)
+                                               return false;
                        }
+               }
 
                /// @TODO
                /// merge with current record, current contents have priority
@@ -1650,7 +1692,7 @@ class dfrn {
                        $changed = true;
 
                        if ($entrytype == DFRN_REPLY_RC)
-                               proc_run("php", "include/notifier.php","comment-import", $current["id"]);
+                               proc_run(PRIORITY_HIGH, "include/notifier.php","comment-import", $current["id"]);
                }
 
                // update last-child if it changes
@@ -2210,7 +2252,7 @@ class dfrn {
 
                                if($posted_id AND $parent AND ($entrytype == DFRN_REPLY_RC)) {
                                        logger("Notifying followers about comment ".$posted_id, LOGGER_DEBUG);
-                                       proc_run("php", "include/notifier.php", "comment-import", $posted_id);
+                                       proc_run(PRIORITY_HIGH, "include/notifier.php", "comment-import", $posted_id);
                                }
 
                                return true;
@@ -2381,7 +2423,7 @@ class dfrn {
 
                                if($entrytype == DFRN_REPLY_RC) {
                                        logger("Notifying followers about deletion of post ".$item["id"], LOGGER_DEBUG);
-                                       proc_run("php", "include/notifier.php","drop", $item["id"]);
+                                       proc_run(PRIORITY_HIGH, "include/notifier.php","drop", $item["id"]);
                                }
                        }
                }