forked from friendica/friendica-addons
Merge pull request #634 from annando/language
"langfilter" uses the new "language" field as well
This commit is contained in:
commit
adb4841bca
1 changed files with 26 additions and 13 deletions
|
@ -153,27 +153,40 @@ function langfilter_prepare_body_content_filter(App $a, &$hook_data)
|
||||||
$read_languages_array = explode(',', $read_languages_string);
|
$read_languages_array = explode(',', $read_languages_string);
|
||||||
|
|
||||||
// Extract the language of the post
|
// Extract the language of the post
|
||||||
$opts = $hook_data['item']['postopts'];
|
if (!empty($hook_data['item']['language'])) {
|
||||||
if (!$opts) {
|
$languages = json_decode($hook_data['item']['language'], true);
|
||||||
// no options associated to post
|
if (!is_array($languages)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!preg_match('/\blang=([^;]*);([^:]*)/', $opts, $matches)) {
|
foreach ($languages as $iso2 => $confidence) {
|
||||||
// no lang options associated to post
|
break;
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$lang = $matches[1];
|
$lang = Text_LanguageDetect_ISO639::code2ToName($iso2);
|
||||||
$confidence = $matches[2];
|
} 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
|
// Do not filter if language detection confidence is too low
|
||||||
if ($minconfidence && $confidence < $minconfidence) {
|
if ($minconfidence && $confidence < $minconfidence) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$iso2 = Text_LanguageDetect_ISO639::nameToCode2($lang);
|
|
||||||
|
|
||||||
if (!$iso2) {
|
if (!$iso2) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue