]> git.mxchange.org Git - friendica.git/blobdiff - include/ostatus.php
Static public is public static
[friendica.git] / include / ostatus.php
index 9472c56e03b175973552ba838adaaa87a7032b8f..78916173e040a99167c8064ef3262ba3a886c75c 100644 (file)
@@ -62,12 +62,26 @@ class ostatus {
                                }
                        }
                }
-
                $author["contact-id"] = $contact["id"];
 
                $found = false;
 
-               if ($author["author-link"] != "") {
+               if ($aliaslink != '') {
+                       $condition = array("`uid` = ? AND `alias` = ? AND `network` != ?",
+                                       $importer["uid"], $aliaslink, NETWORK_STATUSNET);
+                       $r = dba::select('contact', array(), $condition, array('limit' => 1));
+
+                       if (dbm::is_result($r)) {
+                               $found = true;
+                               if ($r['blocked']) {
+                                       $r['id'] = -1;
+                               }
+                               $contact = $r;
+                               $author["contact-id"] = $r["id"];
+                       }
+               }
+
+               if (!$found && ($author["author-link"] != "")) {
                        if ($aliaslink == "") {
                                $aliaslink = $author["author-link"];
                        }
@@ -78,9 +92,11 @@ class ostatus {
 
                        if (dbm::is_result($r)) {
                                $found = true;
+                               if ($r['blocked']) {
+                                       $r['id'] = -1;
+                               }
                                $contact = $r;
                                $author["contact-id"] = $r["id"];
-                               $author["author-link"] = $r["url"];
                        }
                }
 
@@ -90,9 +106,12 @@ class ostatus {
                        $r = dba::select('contact', array(), $condition, array('limit' => 1));
 
                        if (dbm::is_result($r)) {
+                               $found = true;
+                               if ($r['blocked']) {
+                                       $r['id'] = -1;
+                               }
                                $contact = $r;
                                $author["contact-id"] = $r["id"];
-                               $author["author-link"] = $r["url"];
                        }
                }
 
@@ -128,10 +147,16 @@ class ostatus {
                $author["owner-avatar"] = $author["author-avatar"];
 
                // Only update the contacts if it is an OStatus contact
-               if ($r && !$onlyfetch && ($contact["network"] == NETWORK_OSTATUS)) {
+               if ($r && ($r['id'] > 0) && !$onlyfetch && ($contact["network"] == NETWORK_OSTATUS)) {
+
+                       // This contact is vital, so we awake it from the dead
+                       unmark_for_death($contact);
 
                        // Update contact data
 
+                       $current = $contact;
+                       unset($current['name-date']);
+
                        // This query doesn't seem to work
                        // $value = $xpath->query("atom:link[@rel='salmon']", $context)->item(0)->nodeValue;
                        // if ($value != "")
@@ -142,6 +167,9 @@ class ostatus {
                        // if ($value != "")
                        //      $contact["poll"] = $value;
 
+                       $contact['url'] = $author["author-link"];
+                       $contact['nurl'] = normalise_link($contact['url']);
+
                        $value = $xpath->evaluate('atom:author/atom:uri/text()', $context)->item(0)->nodeValue;
                        if ($value != "")
                                $contact["alias"] = $value;
@@ -162,32 +190,25 @@ class ostatus {
                        if ($value != "")
                                $contact["location"] = $value;
 
-                       if (($contact["name"] != $r[0]["name"]) || ($contact["nick"] != $r[0]["nick"]) || ($contact["about"] != $r[0]["about"]) ||
-                               ($contact["alias"] != $r[0]["alias"]) || ($contact["location"] != $r[0]["location"])) {
+                       $contact['name-date'] = datetime_convert();
 
-                               logger("Update contact data for contact ".$contact["id"], LOGGER_DEBUG);
+                       dba::update('contact', $contact, array('id' => $contact["id"]), $current);
 
-                               q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `alias` = '%s', `about` = '%s', `location` = '%s', `name-date` = '%s' WHERE `id` = %d",
-                                       dbesc($contact["name"]), dbesc($contact["nick"]), dbesc($contact["alias"]),
-                                       dbesc($contact["about"]), dbesc($contact["location"]),
-                                       dbesc(datetime_convert()), intval($contact["id"]));
-                       }
-
-                       if (isset($author["author-avatar"]) && ($author["author-avatar"] != $r[0]['avatar'])) {
+                       if (!empty($author["author-avatar"]) && ($author["author-avatar"] != $current['avatar'])) {
                                logger("Update profile picture for contact ".$contact["id"], LOGGER_DEBUG);
-
                                update_contact_avatar($author["author-avatar"], $importer["uid"], $contact["id"]);
                        }
 
                        // Ensure that we are having this contact (with uid=0)
-                       $cid = get_contact($author["author-link"], 0);
+                       $cid = get_contact($aliaslink, 0);
 
                        if ($cid) {
-                               $fields = array('url', 'name', 'nick', 'alias', 'about', 'location');
+                               $fields = array('url', 'nurl', 'name', 'nick', 'alias', 'about', 'location');
                                $old_contact = dba::select('contact', $fields, array('id' => $cid), array('limit' => 1));
 
                                // Update it with the current values
                                $fields = array('url' => $author["author-link"], 'name' => $contact["name"],
+                                               'nurl' => normalise_link($author["author-link"]),
                                                'nick' => $contact["nick"], 'alias' => $contact["alias"],
                                                'about' => $contact["about"], 'location' => $contact["location"],
                                                'success_update' => datetime_convert(), 'last-update' => datetime_convert());
@@ -366,6 +387,11 @@ class ostatus {
                foreach (array_reverse($entrylist) AS $entry) {
                        // fetch the author
                        $authorelement = $xpath->query('/atom:entry/atom:author', $entry);
+
+                       if ($authorelement->length == 0) {
+                               $authorelement = $xpath->query('atom:author', $entry);
+                       }
+
                        if ($authorelement->length > 0) {
                                $author = self::fetchauthor($xpath, $entry, $importer, $contact, $stored);
                        }
@@ -478,6 +504,8 @@ class ostatus {
                                                $found = dba::exists('item', array('uid' => $importer["uid"], 'uri' => $item["uri"]));
                                                if ($found) {
                                                        logger("Item with uri ".$item["uri"]." for user ".$importer["uid"]." already exists.", LOGGER_DEBUG);
+                                               } elseif ($item['contact-id'] < 0) {
+                                                       logger("Item with uri ".$item["uri"]." is from a blocked contact.", LOGGER_DEBUG);
                                                } else {
                                                        // We are having duplicated entries. Hopefully this solves it.
                                                        if (Lock::set('ostatus_process_item_store')) {
@@ -674,7 +702,7 @@ class ostatus {
 
                self::$conv_list[$conversation] = true;
 
-               $conversation_data = z_fetch_url($conversation);
+               $conversation_data = z_fetch_url($conversation, false, $redirects, array('accept_content' => 'application/atom+xml, text/html'));
 
                if (!$conversation_data['success']) {
                        return;
@@ -855,7 +883,7 @@ class ostatus {
                }
 
                $stored = false;
-               $related_data = z_fetch_url($related);
+               $related_data = z_fetch_url($related, false, $redirects, array('accept_content' => 'application/atom+xml, text/html'));
 
                if (!$related_data['success']) {
                        return;