X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FItem.php;h=e54d5fb098e8a79f337814200cc728494f31282a;hb=f81192b4c3838480154301ac25cbbbed58593380;hp=491050c582f2f7d3acff45f30cd052e24196b25b;hpb=b58cabdc414dd11bc84fe0964109ee23213db815;p=friendica.git diff --git a/src/Model/Item.php b/src/Model/Item.php index 491050c582..e54d5fb098 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -138,7 +138,7 @@ class Item 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'post-type', 'post-reason', 'private', 'pubmail', 'visible', 'starred', 'unseen', 'deleted', 'origin', 'mention', 'global', 'network', - 'title', 'content-warning', 'body', 'location', 'coord', 'app', + 'title', 'content-warning', 'body', 'language', 'location', 'coord', 'app', 'rendered-hash', 'rendered-html', 'object-type', 'object', 'target-type', 'target', 'author-id', 'author-link', 'author-name', 'author-avatar', 'author-network', 'owner-id', 'owner-link', 'owner-name', 'owner-avatar', 'causer-id' @@ -1366,7 +1366,7 @@ class Item if ($notify) { DI::contentItem()->postProcessPost($posted_item); if ($copy_permissions && ($posted_item['thr-parent-id'] != $posted_item['uri-id']) && ($posted_item['private'] == self::PRIVATE)) { - DI::contentItem()->copyPermissions($posted_item['thr-parent-id'], $posted_item['uri-id']); + DI::contentItem()->copyPermissions($posted_item['thr-parent-id'], $posted_item['uri-id'], $posted_item['parent-uri-id']); } } else { Hook::callAll('post_remote_end', $posted_item); @@ -1541,7 +1541,25 @@ class Item return; } + $languages = $item['language'] ? array_keys(json_decode($item['language'], true)) : []; + foreach (Tag::getUIDListByURIId($item['uri-id']) as $uid => $tags) { + if (!empty($languages)) { + $keep = false; + $user_languages = User::getWantedLanguages($uid); + foreach ($user_languages as $language) { + if (in_array($language, $languages)) { + $keep = true; + } + } + if ($keep) { + Logger::debug('Wanted languages found', ['uid' => $uid, 'user-languages' => $user_languages, 'item-languages' => $languages]); + } else { + Logger::debug('No wanted languages found', ['uid' => $uid, 'user-languages' => $user_languages, 'item-languages' => $languages]); + continue; + } + } + $stored = self::storeForUserByUriId($item['uri-id'], $uid, ['post-reason' => self::PR_TAG]); Logger::info('Stored item for users', ['uri-id' => $item['uri-id'], 'uid' => $uid, 'stored' => $stored]); foreach ($tags as $tag) { @@ -1996,19 +2014,31 @@ class Item * @return string detected language * @throws \Text_LanguageDetect_Exception */ - private static function getLanguage(array $item): string + private static function getLanguage(array $item): ?string { if (!empty($item['language'])) { return $item['language']; } - if (!in_array($item['gravity'], [self::GRAVITY_PARENT, self::GRAVITY_COMMENT]) || empty($item['body'])) { - return ''; + $transmitted = []; + foreach ($item['transmitted-languages'] ?? [] as $language) { + $transmitted[$language] = 0; } - $languages = self::getLanguageArray($item['title'] . ' ' . ($item['content-warning'] ?? '') . ' ' . $item['body'], 3, $item['uri-id'], $item['author-id']); + $content = trim(($item['title'] ?? '') . ' ' . ($item['content-warning'] ?? '') . ' ' . ($item['body'] ?? '')); + + if (!in_array($item['gravity'], [self::GRAVITY_PARENT, self::GRAVITY_COMMENT]) || empty($content)) { + return !empty($transmitted) ? json_encode($transmitted) : null; + } + + $languages = self::getLanguageArray($content, 3, $item['uri-id'], $item['author-id']); if (empty($languages)) { - return ''; + return !empty($transmitted) ? json_encode($transmitted) : null; + } + + if (!empty($transmitted)) { + $languages = array_merge($transmitted, $languages); + arsort($languages); } return json_encode($languages); @@ -2209,7 +2239,7 @@ class Item // Glue it together to be able to make a hash from it if (!empty($parsed)) { - $host_id = implode('/', $parsed); + $host_id = implode('/', (array)$parsed); } else { $host_id = $uri; } @@ -2554,11 +2584,14 @@ class Item $result = self::insert($datarray2); Logger::info('remote-self post original item', ['contact' => $contact['url'], 'result' => $result, 'item' => $datarray2]); } else { - $datarray['private'] = self::PUBLIC; $datarray['app'] = 'Feed'; $result = true; } + if ($result) { + unset($datarray['private']); + } + return (bool)$result; } @@ -3435,7 +3468,7 @@ class Item unset($urlparts['fragment']); try { - $url = (string)Uri::fromParts($urlparts); + $url = (string)Uri::fromParts((array)$urlparts); } catch (\InvalidArgumentException $e) { DI::logger()->notice('Invalid URL', ['$url' => $url, '$urlparts' => $urlparts]); /* See https://github.com/friendica/friendica/issues/12113 @@ -3743,7 +3776,7 @@ class Item DI::profiler()->startRecording('rendering'); $trailing = ''; foreach ($PostMedias as $PostMedia) { - if (strpos($item['body'], $PostMedia->url)) { + if (strpos($item['body'], (string)$PostMedia->url)) { continue; } @@ -3790,16 +3823,16 @@ class Item foreach ($options as $key => $option) { if ($question['voters'] > 0) { $percent = $option['replies'] / $question['voters'] * 100; - $options[$key]['vote'] = DI::l10n()->tt('%2$s (%3$d%%, %1$d vote)', '%2$s (%3$d%%, %1$d votes)', $option['replies'], $option['name'], round($percent, 1)); + $options[$key]['vote'] = DI::l10n()->tt('%2$s (%3$d%%, %1$d vote)', '%2$s (%3$d%%, %1$d votes)', $option['replies'] ?? 0, $option['name'], round($percent, 1)); } else { - $options[$key]['vote'] = DI::l10n()->tt('%2$s (%1$d vote)', '%2$s (%1$d votes)', $option['replies'], $option['name']); + $options[$key]['vote'] = DI::l10n()->tt('%2$s (%1$d vote)', '%2$s (%1$d votes)', $option['replies'] ?? 0, $option['name']); } } if (!empty($question['voters']) && !empty($question['endtime'])) { - $summary = DI::l10n()->tt('%d voter. Poll end: %s', '%d voters. Poll end: %s', $question['voters'], Temporal::getRelativeDate($question['endtime'])); + $summary = DI::l10n()->tt('%d voter. Poll end: %s', '%d voters. Poll end: %s', $question['voters'] ?? 0, Temporal::getRelativeDate($question['endtime'])); } elseif (!empty($question['voters'])) { - $summary = DI::l10n()->tt('%d voter.', '%d voters.', $question['voters']); + $summary = DI::l10n()->tt('%d voter.', '%d voters.', $question['voters'] ?? 0); } elseif (!empty($question['endtime'])) { $summary = DI::l10n()->t('Poll end: %s', Temporal::getRelativeDate($question['endtime'])); } else {