]> git.mxchange.org Git - friendica-addons.git/blobdiff - appnet/appnet.php
Merge pull request #341 from mexon/pr/retriever1.0
[friendica-addons.git] / appnet / appnet.php
index 171461de184bd7e02dc5243132b9392cf181cc4a..a672e065bbe2068930dc1f60ae0be86baac0ac81 100644 (file)
@@ -2,7 +2,7 @@
 
 /**
  * Name: App.net Connector
- * Description: app.net postings import and export
+ * Description: Bidirectional (posting and reading) connector for app.net.
  * Version: 0.2
  * Author: Michael Vogel <https://pirati.ca/profile/heluecht>
  */
@@ -357,12 +357,12 @@ function appnet_create_entities($a, $b, $postdata) {
                $start = $pos + 1;
        }
 
-       if (isset($postdata["url"]) AND isset($postdata["title"])) {
+       if (isset($postdata["url"]) AND isset($postdata["title"]) AND ($postdata["type"] != "photo")) {
                $postdata["title"] = shortenmsg($postdata["title"], 90);
                $max = 256 - strlen($postdata["title"]);
                $text = shortenmsg($text, $max);
                $text .= "\n[".$postdata["title"]."](".$postdata["url"].")";
-       } elseif (isset($postdata["url"])) {
+       } elseif (isset($postdata["url"]) AND ($postdata["type"] != "photo")) {
                $postdata["url"] = short_link($postdata["url"]);
                $max = 240;
                $text = shortenmsg($text, $max);
@@ -524,7 +524,7 @@ function appnet_send(&$a,&$b) {
                                                "value" => $attached_data
                                                );
 
-               if (isset($post["url"]) AND !isset($post["title"])) {
+               if (isset($post["url"]) AND !isset($post["title"]) AND ($post["type"] != "photo")) {
                        $display_url = str_replace(array("http://www.", "https://www."), array("", ""), $post["url"]);
                        $display_url = str_replace(array("http://", "https://"), array("", ""), $display_url);
 
@@ -1097,28 +1097,36 @@ function appnet_expand_annotations($a, $annotations) {
 
 function appnet_fetchcontact($a, $uid, $contact, $me, $create_user) {
 
-       $r = q("SELECT id FROM unique_contacts WHERE url='%s' LIMIT 1",
-                       dbesc(normalise_link($contact["canonical_url"])));
-
-       if (count($r) == 0)
-               q("INSERT INTO unique_contacts (url, name, nick, avatar) VALUES ('%s', '%s', '%s', '%s')",
-                       dbesc(normalise_link($contact["canonical_url"])),
-                       dbesc($contact["name"]),
-                       dbesc($contact["username"]),
-                       dbesc($contact["avatar_image"]["url"]));
-       else
-               q("UPDATE unique_contacts SET name = '%s', nick = '%s', avatar = '%s' WHERE url = '%s'",
-                       dbesc($contact["name"]),
-                       dbesc($contact["username"]),
-                       dbesc($contact["avatar_image"]["url"]),
-                       dbesc(normalise_link($contact["canonical_url"])));
+       if (function_exists("update_gcontact"))
+               update_gcontact(array("url" => $contact["canonical_url"], "generation" => 2,
+                               "network" => NETWORK_APPNET, "photo" => $contact["avatar_image"]["url"],
+                               "name" => $contact["name"], "nick" => $contact["username"],
+                               "about" => $contact["description"]["text"], "hide" => true,
+                               "addr" => $contact["username"]."@app.net"));
+       else {
+               // Old Code
+               $r = q("SELECT id FROM unique_contacts WHERE url='%s' LIMIT 1",
+                               dbesc(normalise_link($contact["canonical_url"])));
 
-       if (DB_UPDATE_VERSION >= "1177")
-               q("UPDATE `unique_contacts` SET `location` = '%s', `about` = '%s' WHERE url = '%s'",
-                       dbesc(""),
-                       dbesc($contact["description"]["text"]),
-                       dbesc(normalise_link($contact["canonical_url"])));
+               if (count($r) == 0)
+                       q("INSERT INTO unique_contacts (url, name, nick, avatar) VALUES ('%s', '%s', '%s', '%s')",
+                               dbesc(normalise_link($contact["canonical_url"])),
+                               dbesc($contact["name"]),
+                               dbesc($contact["username"]),
+                               dbesc($contact["avatar_image"]["url"]));
+               else
+                       q("UPDATE unique_contacts SET name = '%s', nick = '%s', avatar = '%s' WHERE url = '%s'",
+                               dbesc($contact["name"]),
+                               dbesc($contact["username"]),
+                               dbesc($contact["avatar_image"]["url"]),
+                               dbesc(normalise_link($contact["canonical_url"])));
 
+               if (DB_UPDATE_VERSION >= "1177")
+                       q("UPDATE `unique_contacts` SET `location` = '%s', `about` = '%s' WHERE url = '%s'",
+                               dbesc(""),
+                               dbesc($contact["description"]["text"]),
+                               dbesc(normalise_link($contact["canonical_url"])));
+       }
 
        $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `alias` = '%s' LIMIT 1",
                intval($uid), dbesc("adn::".$contact["id"]));