]> git.mxchange.org Git - friendica-addons.git/blobdiff - appnet/appnet.php
The "id" field is now filled in the notifications. This is needed for the new condens...
[friendica-addons.git] / appnet / appnet.php
index 7e80c6abd2d9471aa3f31c6ece0d688f4e5526af..171461de184bd7e02dc5243132b9392cf181cc4a 100644 (file)
@@ -690,13 +690,19 @@ function appnet_fetchstream($a, $uid) {
        }
        catch (AppDotNetException $e) {
                logger("appnet_fetchstream: Error fetching stream for user ".$uid." ".appnet_error($e->getMessage()));
+               return;
        }
 
+       if (!is_array($stream))
+               $stream = array();
+
        $stream = array_reverse($stream);
        foreach ($stream AS $post) {
                $postarray = appnet_createpost($a, $uid, $post, $me, $user, $ownid, true);
 
                $item = item_store($postarray);
+               $postarray["id"] = $item;
+
                logger('appnet_fetchstream: User '.$uid.' posted stream item '.$item);
 
                $lastid = $post["id"];
@@ -744,8 +750,12 @@ function appnet_fetchstream($a, $uid) {
        }
        catch (AppDotNetException $e) {
                logger("appnet_fetchstream: Error fetching mentions for user ".$uid." ".appnet_error($e->getMessage()));
+               return;
        }
 
+       if (!is_array($mentions))
+               $mentions = array();
+
        $mentions = array_reverse($mentions);
        foreach ($mentions AS $post) {
                $postarray = appnet_createpost($a, $uid, $post, $me, $user, $ownid, false);
@@ -755,6 +765,8 @@ function appnet_fetchstream($a, $uid) {
                        $parent_id = $postarray['parent'];
                } elseif (isset($postarray["body"])) {
                        $item = item_store($postarray);
+                       $postarray["id"] = $item;
+
                        $parent_id = 0;
                        logger('appnet_fetchstream: User '.$uid.' posted mention item '.$item);
                } else {
@@ -888,6 +900,8 @@ function appnet_createpost($a, $uid, $post, $me, $user, $ownid, $createuser, $th
                                foreach ($thread AS $tpost) {
                                        $threadpost = appnet_createpost($a, $uid, $tpost, $me, $user, $ownid, false, false);
                                        $item = item_store($threadpost);
+                                       $threadpost["id"] = $item;
+
                                        logger("appnet_createpost: stored post ".$post["id"]." thread ".$post["thread_id"]." in item ".$item, LOGGER_DEBUG);
                                }
                        //}
@@ -1082,6 +1096,30 @@ 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 (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"]));
 
@@ -1165,6 +1203,14 @@ function appnet_fetchcontact($a, $uid, $contact, $me, $create_user) {
                        intval($contact_id)
                );
 
+               if (DB_UPDATE_VERSION >= "1177")
+                       q("UPDATE `contact` SET `location` = '%s',
+                                               `about` = '%s'
+                                       WHERE `id` = %d",
+                               dbesc(""),
+                               dbesc($contact["description"]["text"]),
+                               intval($contact_id)
+                       );
        } else {
                // update profile photos once every two weeks as we have no notification of when they change.
 
@@ -1206,6 +1252,14 @@ function appnet_fetchcontact($a, $uid, $contact, $me, $create_user) {
                                dbesc($contact["username"]),
                                intval($r[0]['id'])
                        );
+                       if (DB_UPDATE_VERSION >= "1177")
+                               q("UPDATE `contact` SET `location` = '%s',
+                                                       `about` = '%s'
+                                               WHERE `id` = %d",
+                                       dbesc(""),
+                                       dbesc($contact["description"]["text"]),
+                                       intval($r[0]['id'])
+                               );
                }
        }
 
@@ -1265,9 +1319,23 @@ function appnet_cron($a,$b) {
        }
        logger('appnet_cron: cron_start');
 
+       $abandon_days = intval(get_config('system','account_abandon_days'));
+       if ($abandon_days < 1)
+               $abandon_days = 0;
+
+       $abandon_limit = date("Y-m-d H:i:s", time() - $abandon_days * 86400);
+
        $r = q("SELECT * FROM `pconfig` WHERE `cat` = 'appnet' AND `k` = 'import' AND `v` = '1' ORDER BY RAND()");
        if(count($r)) {
                foreach($r as $rr) {
+                       if ($abandon_days != 0) {
+                               $user = q("SELECT `login_date` FROM `user` WHERE uid=%d AND `login_date` >= '%s'", $rr['uid'], $abandon_limit);
+                               if (!count($user)) {
+                                       logger('abandoned account: timeline from user '.$rr['uid'].' will not be imported');
+                                       continue;
+                               }
+                       }
+
                        logger('appnet_cron: importing timeline from user '.$rr['uid']);
                        appnet_fetchstream($a, $rr["uid"]);
                }