]> git.mxchange.org Git - friendica.git/commitdiff
Improve Model\Item::addLanguageInPostopts()
authorHypolite Petovan <mrpetovan@gmail.com>
Sat, 21 Apr 2018 08:11:32 +0000 (04:11 -0400)
committerHypolite Petovan <mrpetovan@gmail.com>
Sat, 21 Apr 2018 08:11:32 +0000 (04:11 -0400)
- Use Content\BBCode::toPlaintext method
- Rename $arr parameter to $item
- Rename $lng variable to $languages

src/Model/Item.php

index 11594486eaa13a86a7bd6b7d69c5a2a1470ef794..db6ba8910538af7d8a892296a9ed84ce72d3a488 100644 (file)
@@ -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;
                }
        }