mirror of
https://github.com/friendica/friendica
synced 2025-04-25 14:30:10 +00:00
Merge remote-tracking branch 'upstream/2022.09-rc' into duplicates
This commit is contained in:
commit
36668dfdb1
15 changed files with 276 additions and 580 deletions
|
@ -1870,23 +1870,40 @@ class Item
|
|||
return '';
|
||||
}
|
||||
|
||||
// Convert attachments to links
|
||||
$naked_body = BBCode::removeAttachment($item['body']);
|
||||
if (empty($naked_body)) {
|
||||
$languages = self::getLanguageArray(trim($item['title'] . "\n" . $item['body']), 3);
|
||||
if (empty($languages)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return json_encode($languages);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a language array from a given text
|
||||
*
|
||||
* @param string $body
|
||||
* @param integer $count
|
||||
* @return array
|
||||
*/
|
||||
public static function getLanguageArray(string $body, int $count): array
|
||||
{
|
||||
// Convert attachments to links
|
||||
$naked_body = BBCode::removeAttachment($body);
|
||||
if (empty($naked_body)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// Remove links and pictures
|
||||
$naked_body = BBCode::removeLinks($naked_body);
|
||||
|
||||
// Convert the title and the body to plain text
|
||||
$naked_body = trim($item['title'] . "\n" . BBCode::toPlaintext($naked_body));
|
||||
$naked_body = BBCode::toPlaintext($naked_body);
|
||||
|
||||
// Remove possibly remaining links
|
||||
$naked_body = preg_replace(Strings::autoLinkRegEx(), '', $naked_body);
|
||||
|
||||
if (empty($naked_body)) {
|
||||
return '';
|
||||
return [];
|
||||
}
|
||||
|
||||
$naked_body = self::getDominantLanguage($naked_body);
|
||||
|
@ -1898,12 +1915,7 @@ class Item
|
|||
$availableLanguages['fa'] = 'fa';
|
||||
|
||||
$ld = new Language(array_keys($availableLanguages));
|
||||
$languages = $ld->detect($naked_body)->limit(0, 3)->close();
|
||||
if (is_array($languages)) {
|
||||
return json_encode($languages);
|
||||
}
|
||||
|
||||
return '';
|
||||
return $ld->detect($naked_body)->limit(0, $count)->close() ?: [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue