]> git.mxchange.org Git - friendica-addons.git/commitdiff
"langfilter" uses the new "language" field as well
authorMichael <heluecht@pirati.ca>
Sat, 30 Jun 2018 05:20:17 +0000 (05:20 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 30 Jun 2018 05:20:17 +0000 (05:20 +0000)
langfilter/langfilter.php

index 42ffb9bb49f51d30f4ae849311153c97dc3679c3..f22034e2e366cd84bd291c9e6fad94d8a9369cb3 100644 (file)
@@ -153,27 +153,40 @@ function langfilter_prepare_body_content_filter(App $a, &$hook_data)
        $read_languages_array = explode(',', $read_languages_string);
 
        // Extract the language of the post
-       $opts = $hook_data['item']['postopts'];
-       if (!$opts) {
-               // no options associated to post
-               return;
-       }
+       if (!empty($hook_data['item']['language'])) {
+               $languages = json_decode($hook_data['item']['language'], true);
+               if (!is_array($languages)) {
+                       return;
+               }
 
-       if (!preg_match('/\blang=([^;]*);([^:]*)/', $opts, $matches)) {
-               // no lang options associated to post
-               return;
-       }
+               foreach ($languages as $iso2 => $confidence) {
+                       break;
+               }
 
-       $lang = $matches[1];
-       $confidence = $matches[2];
+               $lang = Text_LanguageDetect_ISO639::code2ToName($iso2);
+       } else {
+               $opts = $hook_data['item']['postopts'];
+               if (!$opts) {
+                       // no options associated to post
+                       return;
+               }
+
+               if (!preg_match('/\blang=([^;]*);([^:]*)/', $opts, $matches)) {
+                       // no lang options associated to post
+                       return;
+               }
+
+               $lang = $matches[1];
+               $confidence = $matches[2];
+
+               $iso2 = Text_LanguageDetect_ISO639::nameToCode2($lang);
+       }
 
        // Do not filter if language detection confidence is too low
        if ($minconfidence && $confidence < $minconfidence) {
                return;
        }
 
-       $iso2 = Text_LanguageDetect_ISO639::nameToCode2($lang);
-
        if (!$iso2) {
                return;
        }