]> git.mxchange.org Git - friendica.git/blobdiff - include/Contact.php
Merge pull request #2479 from annando/1604-vier-login
[friendica.git] / include / Contact.php
index 831a99c950e0c6e2e9d8ad597435a84d40cedd51..79a14ab581c84dd3de3ab61d9e3efe8174bf27c1 100644 (file)
@@ -129,11 +129,11 @@ function terminate_friendship($user,$self,$contact) {
        }
        elseif($contact['network'] === NETWORK_DIASPORA) {
                require_once('include/diaspora.php');
-               diaspora_unshare($user,$contact);
+               diaspora::send_unshare($user,$contact);
        }
        elseif($contact['network'] === NETWORK_DFRN) {
-               require_once('include/items.php');
-               dfrn_deliver($user,$contact,'placeholder', 1);
+               require_once('include/dfrn.php');
+               dfrn::deliver($user,$contact,'placeholder', 1);
        }
 
 }
@@ -412,12 +412,12 @@ function get_contact($url, $uid = 0) {
                        return 0;
        }
 
-       $contact = q("SELECT `id`, `avatar-date` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d",
+       $contact = q("SELECT `id`, `avatar-date` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d ORDER BY `id` LIMIT 2",
                        dbesc(normalise_link($url)),
                        intval($uid));
 
        if (!$contact)
-               $contact = q("SELECT `id`, `avatar-date` FROM `contact` WHERE `alias` IN ('%s', '%s') AND `uid` = %d",
+               $contact = q("SELECT `id`, `avatar-date` FROM `contact` WHERE `alias` IN ('%s', '%s') AND `uid` = %d ORDER BY `id` LIMIT 1",
                                dbesc($url),
                                dbesc(normalise_link($url)),
                                intval($uid));
@@ -441,9 +441,7 @@ function get_contact($url, $uid = 0) {
        if (!in_array($data["network"], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA)))
                return 0;
 
-       // tempory programming. Can be deleted after 2015-02-07
-       if (($data["alias"] == "") AND (normalise_link($data["url"]) != normalise_link($url)))
-               $data["alias"] = normalise_link($url);
+       $url = $data["url"];
 
        if ($contactid == 0) {
                q("INSERT INTO `contact` (`uid`, `created`, `url`, `nurl`, `addr`, `alias`, `notify`, `poll`,
@@ -472,7 +470,7 @@ function get_contact($url, $uid = 0) {
                        dbesc($data["poco"])
                );
 
-               $contact = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d",
+               $contact = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d ORDER BY `id` LIMIT 2",
                                dbesc(normalise_link($data["url"])),
                                intval($uid));
                if (!$contact)
@@ -481,23 +479,23 @@ function get_contact($url, $uid = 0) {
                $contactid = $contact[0]["id"];
        }
 
+       if ((count($contact) > 1) AND ($uid == 0) AND ($contactid != 0) AND ($url != ""))
+               q("DELETE FROM `contact` WHERE `nurl` = '%s' AND `id` != %d",
+                       dbesc(normalise_link($url)),
+                       intval($contactid));
+
        require_once("Photo.php");
 
-       $photos = import_profile_photo($data["photo"],$uid,$contactid);
+       update_contact_avatar($data["photo"],$uid,$contactid);
 
-       q("UPDATE `contact` SET `photo` = '%s', `thumb` = '%s', `micro` = '%s',
-               `addr` = '%s', `alias` = '%s', `name` = '%s', `nick` = '%s',
-               `name-date` = '%s', `uri-date` = '%s', `avatar-date` = '%s' WHERE `id` = %d",
-               dbesc($photos[0]),
-               dbesc($photos[1]),
-               dbesc($photos[2]),
+       q("UPDATE `contact` SET `addr` = '%s', `alias` = '%s', `name` = '%s', `nick` = '%s',
+               `name-date` = '%s', `uri-date` = '%s' WHERE `id` = %d",
                dbesc($data["addr"]),
                dbesc($data["alias"]),
                dbesc($data["name"]),
                dbesc($data["nick"]),
                dbesc(datetime_convert()),
                dbesc(datetime_convert()),
-               dbesc(datetime_convert()),
                intval($contactid)
        );
 
@@ -557,60 +555,6 @@ function posts_from_gcontact($a, $gcontact_id) {
        return $o;
 }
 
-/**
- * @brief set the gcontact-id in all item entries
- *
- * This job has to be started multiple times until all entries are set.
- * It isn't started in the update function since it would consume too much time and can be done in the background.
- */
-function item_set_gcontact() {
-       define ('POST_UPDATE_VERSION', 1192);
-
-       // Was the script completed?
-       if (get_config("system", "post_update_version") >= POST_UPDATE_VERSION)
-               return;
-
-       // Check if the first step is done (Setting "gcontact-id" in the item table)
-       $r = q("SELECT `author-link`, `author-name`, `author-avatar`, `uid`, `network` FROM `item` WHERE `gcontact-id` = 0 LIMIT 1000");
-       if (!$r) {
-               // Are there unfinished entries in the thread table?
-               $r = q("SELECT COUNT(*) AS `total` FROM `thread`
-                       INNER JOIN `item` ON `item`.`id` =`thread`.`iid`
-                       WHERE `thread`.`gcontact-id` = 0 AND
-                               (`thread`.`uid` IN (SELECT `uid` from `user`) OR `thread`.`uid` = 0)");
-
-               if ($r AND ($r[0]["total"] == 0)) {
-                       set_config("system", "post_update_version", POST_UPDATE_VERSION);
-                       return false;
-               }
-
-               // Update the thread table from the item table
-               q("UPDATE `thread` INNER JOIN `item` ON `item`.`id`=`thread`.`iid`
-                               SET `thread`.`gcontact-id` = `item`.`gcontact-id`
-                       WHERE `thread`.`gcontact-id` = 0 AND
-                               (`thread`.`uid` IN (SELECT `uid` from `user`) OR `thread`.`uid` = 0)");
-
-               return false;
-       }
-
-       $item_arr = array();
-       foreach ($r AS $item) {
-               $index = $item["author-link"]."-".$item["uid"];
-               $item_arr[$index] = array("author-link" => $item["author-link"],
-                                               "uid" => $item["uid"],
-                                               "network" => $item["network"]);
-       }
-
-       // Set the "gcontact-id" in the item table and add a new gcontact entry if needed
-       foreach($item_arr AS $item) {
-               $gcontact_id = get_gcontact_id(array("url" => $item['author-link'], "network" => $item['network'],
-                                               "photo" => $item['author-avatar'], "name" => $item['author-name']));
-               q("UPDATE `item` SET `gcontact-id` = %d WHERE `uid` = %d AND `author-link` = '%s' AND `gcontact-id` = 0",
-                       intval($gcontact_id), intval($item["uid"]), dbesc($item["author-link"]));
-       }
-       return true;
-}
-
 /**
  * @brief Returns posts from a given contact
  *