X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FProtocol%2FFeed.php;h=42f470e23f1ba01f2b33bd48c592ccb8658201c7;hb=b84c68f02455ea6d2a4384229535c45d6426fe4b;hp=5d682d837eb2517865383176ff05515853aa60b9;hpb=8bc799ff387cd4a499620b3d7c3d7b589755f991;p=friendica.git diff --git a/src/Protocol/Feed.php b/src/Protocol/Feed.php index 5d682d837e..42f470e23f 100644 --- a/src/Protocol/Feed.php +++ b/src/Protocol/Feed.php @@ -1,6 +1,6 @@ $item['created'], 'uid' => $item['uid'], 'uri' => $item['uri']]); continue; - } elseif (Item::tooOld($item)) { + } elseif (Item::isTooOld($item)) { Logger::info('Feed is too old', ['created' => $item['created'], 'uid' => $item['uid'], 'uri' => $item['uri']]); continue; } @@ -543,7 +484,7 @@ class Feed $item["body"] = trim($item["title"]); } - $data = ParseUrl::getSiteinfoCached($item['plink'], true); + $data = ParseUrl::getSiteinfoCached($item['plink']); if (!empty($data['text']) && !empty($data['title']) && (mb_strlen($item['body']) < mb_strlen($data['text']))) { // When the fetched page info text is longer than the body, we do try to enhance the body if (!empty($item['body']) && (strpos($data['title'], $item['body']) === false) && (strpos($data['text'], $item['body']) === false)) { @@ -598,6 +539,10 @@ class Feed } } + if (empty($item['title'])) { + $item['post-type'] = Item::PT_NOTE; + } + Logger::info('Stored feed', ['item' => $item]); $notify = Item::isRemoteSelf($contact, $item); @@ -606,7 +551,7 @@ class Feed // Additionally we have to avoid conflicts with identical URI between imported feeds and these items. if ($notify) { $item['guid'] = Item::guidFromUri($orig_plink, DI::baseUrl()->getHostname()); - unset($item['uri']); + $item['uri'] = Item::newURI($item['uid'], $item['guid']); unset($item['thr-parent']); unset($item['parent-uri']); @@ -614,17 +559,27 @@ class Feed $notify = PRIORITY_MEDIUM; } - $postings[] = ['item' => $item, 'notify' => $notify, - 'taglist' => $taglist, 'attachments' => $attachments]; + $condition = ['uid' => $item['uid'], 'uri' => $item['uri']]; + if (!Post::exists($condition) && !Post\Delayed::exists($item["uri"], $item['uid'])) { + if (!$notify) { + Post\Delayed::publish($item, $notify, $taglist, $attachments); + } else { + $postings[] = ['item' => $item, 'notify' => $notify, + 'taglist' => $taglist, 'attachments' => $attachments]; + } + } else { + Logger::info('Post already created or exists in the delayed posts queue', ['uid' => $item['uid'], 'uri' => $item["uri"]]); + } } if (!empty($postings)) { + $min_posting = DI::config()->get('system', 'minimum_posting_interval', 0); $total = count($postings); if ($total > 1) { // Posts shouldn't be delayed more than a day $interval = min(1440, self::getPollInterval($contact)); - $delay = round(($interval * 60) / $total); - Logger::notice('Got posting delay', ['delay' => $delay, 'interval' => $interval, 'items' => $total, 'cid' => $contact['id'], 'url' => $contact['url']]); + $delay = max(round(($interval * 60) / $total), 60 * $min_posting); + Logger::info('Got posting delay', ['delay' => $delay, 'interval' => $interval, 'items' => $total, 'cid' => $contact['id'], 'url' => $contact['url']]); } else { $delay = 0; } @@ -633,15 +588,20 @@ class Feed foreach ($postings as $posting) { if ($delay > 0) { - $publish_at = DateTimeFormat::utc('now + ' . $post_delay . ' second'); - Logger::notice('Got publishing date', ['delay' => $delay, 'publish_at' => $publish_at, 'cid' => $contact['id'], 'url' => $contact['url']]); + $publish_time = time() + $post_delay; $post_delay += $delay; } else { - $publish_at = DBA::NULL_DATETIME; + $publish_time = time(); + } + + $last_publish = DI::pConfig()->get($posting['item']['uid'], 'system', 'last_publish', 0, true); + $next_publish = max($last_publish + (60 * $min_posting), time()); + if ($publish_time < $next_publish) { + $publish_time = $next_publish; } + $publish_at = date(DateTimeFormat::MYSQL, $publish_time); - Worker::add(['priority' => PRIORITY_HIGH, 'delayed' => $publish_at], - 'DelayedPublish', $posting['item'], $posting['notify'], $posting['taglist'], $posting['attachments']); + Post\Delayed::add($posting['item']['uri'], $posting['item'], $posting['notify'], false, $publish_at, $posting['taglist'], $posting['attachments']); } } @@ -931,12 +891,12 @@ class Feed $params = ['order' => ['received' => true], 'limit' => $max_items]; if ($filter === 'posts') { - $ret = Item::selectThread([], $condition, $params); + $ret = Post::selectThread(Item::DELIVER_FIELDLIST, $condition, $params); } else { - $ret = Item::select([], $condition, $params); + $ret = Post::select(Item::DELIVER_FIELDLIST, $condition, $params); } - $items = Item::inArray($ret); + $items = Post::toArray($ret); $doc = new DOMDocument('1.0', 'utf-8'); $doc->formatOutput = true; @@ -998,7 +958,7 @@ class Feed XML::addElement($doc, $root, "id", DI::baseUrl() . "/profile/" . $owner["nick"]); XML::addElement($doc, $root, "title", $title); XML::addElement($doc, $root, "subtitle", sprintf("Updates from %s on %s", $owner["name"], DI::config()->get('config', 'sitename'))); - XML::addElement($doc, $root, "logo", $owner["photo"]); + XML::addElement($doc, $root, "logo", Contact::getAvatarUrlForId($owner['id'], Proxy::SIZE_SMALL, $owner['updated'])); XML::addElement($doc, $root, "updated", DateTimeFormat::utcNow(DateTimeFormat::ATOM)); $author = self::addAuthor($doc, $owner); @@ -1085,7 +1045,7 @@ class Feed $condition = ['uid' => $owner["uid"], 'guid' => $repeated_guid, 'private' => [Item::PUBLIC, Item::UNLISTED], 'network' => Protocol::FEDERATED]; - $repeated_item = Item::selectFirst([], $condition); + $repeated_item = Post::selectFirst(Item::DELIVER_FIELDLIST, $condition); if (!DBA::isResult($repeated_item)) { return false; } @@ -1177,9 +1137,9 @@ class Feed $mentioned = []; if ($item['gravity'] != GRAVITY_PARENT) { - $parent = Item::selectFirst(['guid', 'author-link', 'owner-link'], ['id' => $item['parent']]); + $parent = Post::selectFirst(['guid', 'author-link', 'owner-link'], ['id' => $item['parent']]); - $thrparent = Item::selectFirst(['guid', 'author-link', 'owner-link', 'plink'], ['uid' => $owner["uid"], 'uri' => $item['thr-parent']]); + $thrparent = Post::selectFirst(['guid', 'author-link', 'owner-link', 'plink'], ['uid' => $owner["uid"], 'uri' => $item['thr-parent']]); if (DBA::isResult($thrparent)) { $mentioned[$thrparent["author-link"]] = $thrparent["author-link"];