]> git.mxchange.org Git - friendica.git/blobdiff - include/socgraph.php
Or back ...
[friendica.git] / include / socgraph.php
index 8ad7a4cd31104ace048e793de8d055d206d8995a..33d62dc5b9abba5030c28706ab53237c9b76ab7d 100644 (file)
@@ -11,7 +11,7 @@ require_once('include/datetime.php');
 require_once("include/Scrape.php");
 require_once("include/html2bbcode.php");
 require_once("include/Contact.php");
-
+require_once("include/Photo.php");
 
 /*
  * poco_load
@@ -438,44 +438,47 @@ function poco_last_updated($profile, $force = false) {
 
                                $noscrape = json_decode($noscraperet["body"], true);
 
-                               $contact = array("url" => $profile,
-                                               "network" => $server[0]["network"],
-                                               "generation" => $gcontacts[0]["generation"]);
+                               if (is_array($noscrape)) {
+                                       $contact = array("url" => $profile,
+                                                       "network" => $server[0]["network"],
+                                                       "generation" => $gcontacts[0]["generation"]);
 
-                               $contact["name"] = $noscrape["fn"];
-                               $contact["community"] = $noscrape["comm"];
+                                       $contact["name"] = $noscrape["fn"];
+                                       $contact["community"] = $noscrape["comm"];
 
-                               if (isset($noscrape["tags"])) {
-                                       $keywords = implode(" ", $noscrape["tags"]);
-                                       if ($keywords != "")
-                                               $contact["keywords"] = $keywords;
-                               }
+                                       if (isset($noscrape["tags"])) {
+                                               $keywords = implode(" ", $noscrape["tags"]);
+                                               if ($keywords != "")
+                                                       $contact["keywords"] = $keywords;
+                                       }
+
+                                       $location = formatted_location($noscrape);
+                                       if ($location)
+                                               $contact["location"] = $location;
+
+                                       $contact["notify"] = $noscrape["dfrn-notify"];
+
+                                       // Remove all fields that are not present in the gcontact table
+                                       unset($noscrape["fn"]);
+                                       unset($noscrape["key"]);
+                                       unset($noscrape["homepage"]);
+                                       unset($noscrape["comm"]);
+                                       unset($noscrape["tags"]);
+                                       unset($noscrape["locality"]);
+                                       unset($noscrape["region"]);
+                                       unset($noscrape["country-name"]);
+                                       unset($noscrape["contacts"]);
+                                       unset($noscrape["dfrn-request"]);
+                                       unset($noscrape["dfrn-confirm"]);
+                                       unset($noscrape["dfrn-notify"]);
+                                       unset($noscrape["dfrn-poll"]);
+
+                                       $contact = array_merge($contact, $noscrape);
 
-                               $location = formatted_location($noscrape);
-                               if ($location)
-                                       $contact["location"] = $location;
-
-                               $contact["notify"] = $noscrape["dfrn-notify"];
-
-                               // Remove all fields that are not present in the gcontact table
-                               unset($noscrape["fn"]);
-                               unset($noscrape["key"]);
-                               unset($noscrape["homepage"]);
-                               unset($noscrape["comm"]);
-                               unset($noscrape["tags"]);
-                               unset($noscrape["locality"]);
-                               unset($noscrape["region"]);
-                               unset($noscrape["country-name"]);
-                               unset($noscrape["contacts"]);
-                               unset($noscrape["dfrn-request"]);
-                               unset($noscrape["dfrn-confirm"]);
-                               unset($noscrape["dfrn-notify"]);
-                               unset($noscrape["dfrn-poll"]);
-
-                               $contact = array_merge($contact, $noscrape);
-                               update_gcontact($contact);
-
-                               return $noscrape["updated"];
+                                       update_gcontact($contact);
+
+                                       return $noscrape["updated"];
+                               }
                        }
                }
        }
@@ -719,7 +722,8 @@ function poco_check_server($server_url, $network = "", $force = false) {
                // Will also return data for Friendica and GNU Social - but it will be overwritten later
                // The "not implemented" is a special treatment for really, really old Friendica versions
                $serverret = z_fetch_url($server_url."/api/statusnet/version.json");
-               if ($serverret["success"] AND ($serverret["body"] != '{"error":"not implemented"}') AND ($serverret["body"] != '') AND (strlen($serverret["body"]) < 250)) {
+               if ($serverret["success"] AND ($serverret["body"] != '{"error":"not implemented"}') AND
+                       ($serverret["body"] != '') AND (strlen($serverret["body"]) < 30)) {
                        $platform = "StatusNet";
                        $version = trim($serverret["body"], '"');
                        $network = NETWORK_OSTATUS;
@@ -727,7 +731,8 @@ function poco_check_server($server_url, $network = "", $force = false) {
 
                // Test for GNU Social
                $serverret = z_fetch_url($server_url."/api/gnusocial/version.json");
-               if ($serverret["success"] AND ($serverret["body"] != '{"error":"not implemented"}') AND ($serverret["body"] != '') AND (strlen($serverret["body"]) < 250)) {
+               if ($serverret["success"] AND ($serverret["body"] != '{"error":"not implemented"}') AND
+                       ($serverret["body"] != '') AND (strlen($serverret["body"]) < 30)) {
                        $platform = "GNU Social";
                        $version = trim($serverret["body"], '"');
                        $network = NETWORK_OSTATUS;
@@ -854,6 +859,11 @@ function poco_check_server($server_url, $network = "", $force = false) {
        // Check again if the server exists
        $servers = q("SELECT `nurl` FROM `gserver` WHERE `nurl` = '%s'", dbesc(normalise_link($server_url)));
 
+       $version = strip_tags($version);
+       $site_name = strip_tags($site_name);
+       $info = strip_tags($info);
+       $platform = strip_tags($platform);
+
        if ($servers)
                 q("UPDATE `gserver` SET `url` = '%s', `version` = '%s', `site_name` = '%s', `info` = '%s', `register_policy` = %d, `poco` = '%s', `noscrape` = '%s',
                        `network` = '%s', `platform` = '%s', `last_contact` = '%s', `last_failure` = '%s' WHERE `nurl` = '%s'",
@@ -1422,6 +1432,14 @@ function update_gcontact($contact) {
        unset($fields["url"]);
        unset($fields["updated"]);
 
+       // Bugfix: We had an error in the storing of keywords which lead to the "0"
+       // This value is still transmitted via poco.
+       if ($contact["keywords"] == "0")
+               unset($contact["keywords"]);
+
+       if ($r[0]["keywords"] == "0")
+               $r[0]["keywords"] = "";
+
        // assign all unassigned fields from the database entry
        foreach ($fields AS $field => $data)
                if (!isset($contact[$field]) OR ($contact[$field] == ""))
@@ -1433,6 +1451,28 @@ function update_gcontact($contact) {
        if (!isset($contact["updated"]))
                $contact["updated"] = datetime_convert();
 
+       if ($contact["server_url"] == "") {
+               $server_url = $contact["url"];
+
+               $server_url = matching_url($server_url, $contact["alias"]);
+               if ($server_url != "")
+                       $contact["server_url"] = $server_url;
+
+               $server_url = matching_url($server_url, $contact["photo"]);
+               if ($server_url != "")
+                       $contact["server_url"] = $server_url;
+
+               $server_url = matching_url($server_url, $contact["notify"]);
+               if ($server_url != "")
+                       $contact["server_url"] = $server_url;
+       } else
+               $contact["server_url"] = normalise_link($contact["server_url"]);
+
+       if (($contact["addr"] == "") AND ($contact["server_url"] != "") AND ($contact["nick"] != "")) {
+               $hostname = str_replace("http://", "", $contact["server_url"]);
+               $contact["addr"] = $contact["nick"]."@".$hostname;
+       }
+
        // Check if any field changed
        $update = false;
        unset($fields["generation"]);
@@ -1467,6 +1507,28 @@ function update_gcontact($contact) {
                        intval($contact["generation"]), dbesc($contact["updated"]),
                        dbesc($contact["server_url"]), dbesc($contact["connect"]),
                        dbesc(normalise_link($contact["url"])), intval($contact["generation"]));
+
+
+               // Now update the contact entry with the user id "0" as well.
+               // This is used for the shadow copies of public items.
+               $r = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = 0 ORDER BY `id` LIMIT 1",
+                       dbesc(normalise_link($contact["url"])));
+
+               if ($r) {
+                       logger("Update shadow contact ".$r[0]["id"], LOGGER_DEBUG);
+
+                       update_contact_avatar($contact["photo"], 0, $r[0]["id"]);
+
+                       q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `addr` = '%s',
+                                               `network` = '%s', `bd` = '%s', `gender` = '%s',
+                                               `keywords` = '%s', `alias` = '%s', `url` = '%s',
+                                               `location` = '%s', `about` = '%s'
+                                       WHERE `id` = %d",
+                               dbesc($contact["name"]), dbesc($contact["nick"]), dbesc($contact["addr"]),
+                               dbesc($contact["network"]), dbesc($contact["birthday"]), dbesc($contact["gender"]),
+                               dbesc($contact["keywords"]), dbesc($contact["alias"]), dbesc($contact["url"]),
+                               dbesc($contact["location"]), dbesc($contact["about"]), intval($r[0]["id"]));
+               }
        }
 
        return $gcontact_id;