From: Hypolite Petovan Date: Sat, 21 Apr 2018 08:11:32 +0000 (-0400) Subject: Improve Model\Item::addLanguageInPostopts() X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=abc50eb3aed2ed2a6fef207cfaea033689e0779e;p=friendica.git Improve Model\Item::addLanguageInPostopts() - Use Content\BBCode::toPlaintext method - Rename $arr parameter to $item - Rename $lng variable to $languages --- diff --git a/src/Model/Item.php b/src/Model/Item.php index 11594486ea..db6ba89105 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -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; } }