X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=appnet%2Fappnet.php;h=171461de184bd7e02dc5243132b9392cf181cc4a;hb=bcd20d576323459cef0909239e5e80d8b36e16eb;hp=b5765ab5bb43b38c870e12c6f869637202539ee0;hpb=9177ee2ecb07a3b6d0bc0b938ab8c90c62ce7554;p=friendica-addons.git diff --git a/appnet/appnet.php b/appnet/appnet.php index b5765ab5..171461de 100644 --- a/appnet/appnet.php +++ b/appnet/appnet.php @@ -12,6 +12,7 @@ - Use embedded pictures for the attachment information (large attachment) - Sound links must be handled - https://alpha.app.net/sr_rolando/post/32365203 - double pictures + - https://alpha.app.net/opendev/post/34396399 - location data */ define('APPNET_DEFAULT_POLL_INTERVAL', 5); // given in minutes @@ -689,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"]; @@ -715,7 +722,7 @@ function appnet_fetchstream($a, $uid) { 'to_email' => $user['email'], 'uid' => $user['uid'], 'item' => $postarray, - 'link' => $a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $item, + 'link' => $a->get_baseurl().'/display/'.urlencode(get_item_guid($item)), 'source_name' => $postarray['author-name'], 'source_link' => $postarray['author-link'], 'source_photo' => $postarray['author-avatar'], @@ -743,23 +750,47 @@ 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); - if (isset($postarray["id"])) + if (isset($postarray["id"])) { $item = $postarray["id"]; - elseif (isset($postarray["body"])) { + $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 + } else { $item = 0; + $parent_id = 0; + } + + // Fetch the parent and id + if (($parent_id == 0) AND ($postarray['uri'] != "")) { + $r = q("SELECT `id`, `parent` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", + dbesc($postarray['uri']), + intval($uid) + ); + + if (count($r)) { + $item = $r[0]['id']; + $parent_id = $r[0]['parent']; + } + } $lastid = $post["id"]; - if (($item != 0) AND ($postarray['contact-id'] != $me["id"])) { + //if (($item != 0) AND ($postarray['contact-id'] != $me["id"])) { + if ($item != 0) { require_once('include/enotify.php'); notification(array( 'type' => NOTIFY_TAGSELF, @@ -769,12 +800,13 @@ function appnet_fetchstream($a, $uid) { 'to_email' => $user['email'], 'uid' => $user['uid'], 'item' => $postarray, - 'link' => $a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $item, + 'link' => $a->get_baseurl().'/display/'.urlencode(get_item_guid($item)), 'source_name' => $postarray['author-name'], 'source_link' => $postarray['author-link'], 'source_photo' => $postarray['author-avatar'], 'verb' => ACTIVITY_TAG, - 'otype' => 'item' + 'otype' => 'item', + 'parent' => $parent_id, )); } } @@ -790,7 +822,7 @@ function appnet_fetchstream($a, $uid) { */ } -function appnet_createpost($a, $uid, $post, $me, $user, $ownid, $createuser, $threadcompletion = true) { +function appnet_createpost($a, $uid, $post, $me, $user, $ownid, $createuser, $threadcompletion = true, $nodupcheck = false) { require_once('include/items.php'); if ($post["machine_only"]) @@ -805,25 +837,33 @@ function appnet_createpost($a, $uid, $post, $me, $user, $ownid, $createuser, $th $postarray['wall'] = 0; $postarray['verb'] = ACTIVITY_POST; $postarray['network'] = dbesc(NETWORK_APPNET); - $postarray['uri'] = "adn::".$post["id"]; + if (is_array($post["repost_of"])) { + // You can't reply to reposts. So use the original id and thread-id + $postarray['uri'] = "adn::".$post["repost_of"]["id"]; + $postarray['parent-uri'] = "adn::".$post["repost_of"]["thread_id"]; + } else { + $postarray['uri'] = "adn::".$post["id"]; + $postarray['parent-uri'] = "adn::".$post["thread_id"]; + } - $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", - dbesc($postarray['uri']), - intval($uid) - ); + if (!$nodupcheck) { + $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", + dbesc($postarray['uri']), + intval($uid) + ); - if (count($r)) - return($r[0]); + if (count($r)) + return($r[0]); - $r = q("SELECT * FROM `item` WHERE `extid` = '%s' AND `uid` = %d LIMIT 1", - dbesc($postarray['uri']), - intval($uid) - ); + $r = q("SELECT * FROM `item` WHERE `extid` = '%s' AND `uid` = %d LIMIT 1", + dbesc($postarray['uri']), + intval($uid) + ); - if (count($r)) - return($r[0]); + if (count($r)) + return($r[0]); + } - $postarray['parent-uri'] = "adn::".$post["thread_id"]; if (isset($post["reply_to"]) AND ($post["reply_to"] != "")) { $postarray['thr-parent'] = "adn::".$post["reply_to"]; @@ -860,16 +900,20 @@ 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); } //} } // Don't create accounts of people who just comment something $createuser = false; - } else - $postarray['thr-parent'] = $postarray['uri']; - $postarray['plink'] = $post["canonical_url"]; + $postarray['object-type'] = ACTIVITY_OBJ_COMMENT; + } else { + $postarray['thr-parent'] = $postarray['uri']; + $postarray['object-type'] = ACTIVITY_OBJ_NOTE; + } if (($post["user"]["id"] != $ownid) OR ($postarray['thr-parent'] == $postarray['uri'])) { $postarray['owner-name'] = $post["user"]["name"]; @@ -899,6 +943,8 @@ function appnet_createpost($a, $uid, $post, $me, $user, $ownid, $createuser, $th $content = $post; } + $postarray['plink'] = $content["canonical_url"]; + if (is_array($content["entities"])) { $converted = appnet_expand_entities($a, $content["text"], $content["entities"]); $postarray['body'] = $converted["body"]; @@ -912,7 +958,7 @@ function appnet_createpost($a, $uid, $post, $me, $user, $ownid, $createuser, $th $links[$url] = $link["url"]; } - if (sizeof($content["annotations"])) + /* if (sizeof($content["annotations"])) foreach($content["annotations"] AS $annotation) { if ($annotation[type] == "net.app.core.oembed") { if (isset($annotation["value"]["embeddable_url"])) { @@ -921,7 +967,6 @@ function appnet_createpost($a, $uid, $post, $me, $user, $ownid, $createuser, $th unset($links[$url]); } } elseif ($annotation[type] == "com.friendica.post") { - // Nur zum Testen deaktiviert //$links = array(); //if (isset($annotation["value"]["post-title"])) // $postarray['title'] = $annotation["value"]["post-title"]; @@ -942,7 +987,7 @@ function appnet_createpost($a, $uid, $post, $me, $user, $ownid, $createuser, $th $postarray['author-avatar'] = $annotation["value"]["author-avatar"]; } - } + } */ $page_info = ""; @@ -952,19 +997,24 @@ function appnet_createpost($a, $uid, $post, $me, $user, $ownid, $createuser, $th $page_info = "\n[url=".$photo["url"]."][img]".$photo["large"]."[/img][/url]"; elseif ($photo["url"] != "") $page_info = "\n[img]".$photo["url"]."[/img]"; + + if ($photo["url"] != "") + $postarray['object-type'] = ACTIVITY_OBJ_IMAGE; + } else $photo = array("url" => "", "large" => ""); if (sizeof($links)) { $link = array_pop($links); - $url = "[url=".$link."]".$link."[/url]"; - - $removedlink = trim(str_replace($url, "", $postarray['body'])); - - if (($removedlink == "") OR strstr($postarray['body'], $removedlink)) - $postarray['body'] = $removedlink; + $url = str_replace(array('/', '.'), array('\/', '\.'), $link); $page_info = add_page_info($link, false, $photo["url"]); + + if (trim($page_info) != "") { + $removedlink = preg_replace("/\[url\=".$url."\](.*?)\[\/url\]/ism", '', $postarray['body']); + if (($removedlink == "") OR strstr($postarray['body'], $removedlink)) + $postarray['body'] = $removedlink; + } } $postarray['body'] .= $page_info; @@ -1046,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"])); @@ -1129,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. @@ -1170,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']) + ); } } @@ -1229,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"]); }