mirror of
https://github.com/friendica/friendica
synced 2024-12-23 16:40:17 +00:00
Improve Model\Item::addLanguageInPostopts()
- Use Content\BBCode::toPlaintext method - Rename $arr parameter to $item - Rename $lng variable to $languages
This commit is contained in:
parent
ec9baef968
commit
abc50eb3ae
1 changed files with 11 additions and 11 deletions
|
@ -978,35 +978,35 @@ class Item extends BaseObject
|
|||
* if possible and not already present.
|
||||
* Expects "body" element to exist in $arr.
|
||||
*/
|
||||
private static function addLanguageInPostopts(&$arr)
|
||||
private static function addLanguageInPostopts(&$item)
|
||||
{
|
||||
if (x($arr, 'postopts')) {
|
||||
if (strstr($arr['postopts'], 'lang=')) {
|
||||
if (!empty($item['postopts'])) {
|
||||
if (strstr($item['postopts'], 'lang=')) {
|
||||
// do not override
|
||||
return;
|
||||
}
|
||||
$postopts = $arr['postopts'];
|
||||
$postopts = $item['postopts'];
|
||||
} else {
|
||||
$postopts = "";
|
||||
}
|
||||
|
||||
$naked_body = preg_replace('/\[(.+?)\]/','', $arr['body']);
|
||||
$l = new Text_LanguageDetect();
|
||||
$lng = $l->detect($naked_body, 3);
|
||||
$naked_body = Text\BBCode::toPlaintext($item['body'], false);
|
||||
|
||||
if (sizeof($lng) > 0) {
|
||||
if ($postopts != "") {
|
||||
$languages = (new Text_LanguageDetect())->detect($naked_body, 3);
|
||||
|
||||
if (sizeof($languages) > 0) {
|
||||
if ($postopts != '') {
|
||||
$postopts .= '&'; // arbitrary separator, to be reviewed
|
||||
}
|
||||
|
||||
$postopts .= 'lang=';
|
||||
$sep = "";
|
||||
|
||||
foreach ($lng as $language => $score) {
|
||||
foreach ($languages as $language => $score) {
|
||||
$postopts .= $sep . $language . ";" . $score;
|
||||
$sep = ':';
|
||||
}
|
||||
$arr['postopts'] = $postopts;
|
||||
$item['postopts'] = $postopts;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue