Merge pull request #8052 from annando/contentmap

AP: Transmit the language in the contentMap
This commit is contained in:
Philipp 2020-01-04 23:07:57 +01:00 committed by GitHub
commit 729277529f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1304,12 +1304,17 @@ class Transmitter
$data['content'] = BBCode::convert($body, false, 9); $data['content'] = BBCode::convert($body, false, 9);
} }
// The regular "content" field does contain a minimized HTML. This is done since systems like
// Mastodon has got problems with - for example - embedded pictures.
// The contentMap does contain the unmodified HTML.
$language = self::getLanguage($item);
if (!empty($language)) {
$regexp = "/[@!]\[url\=([^\[\]]*)\].*?\[\/url\]/ism"; $regexp = "/[@!]\[url\=([^\[\]]*)\].*?\[\/url\]/ism";
$richbody = preg_replace_callback($regexp, ['self', 'mentionCallback'], $item['body']); $richbody = preg_replace_callback($regexp, ['self', 'mentionCallback'], $item['body']);
$richbody = BBCode::removeAttachment($richbody); $richbody = BBCode::removeAttachment($richbody);
$data['contentMap']['text/html'] = BBCode::convert($richbody, false); $data['contentMap'][$language] = BBCode::convert($richbody, false);
$data['contentMap']['text/markdown'] = BBCode::toMarkdown($item["body"]); }
$data['source'] = ['content' => $item['body'], 'mediaType' => "text/bbcode"]; $data['source'] = ['content' => $item['body'], 'mediaType' => "text/bbcode"];
@ -1333,6 +1338,35 @@ class Transmitter
return $data; return $data;
} }
/**
* Fetches the language from the post, the user or the system.
*
* @param array $item
*
* @return string language string
*/
private static function getLanguage(array $item)
{
// Try to fetch the language from the post itself
if (!empty($item['language'])) {
$languages = array_keys(json_decode($item['language'], true));
if (!empty($languages[0])) {
return $languages[0];
}
}
// Otherwise use the user's language
if (!empty($item['uid'])) {
$user = DBA::selectFirst('user', ['language'], ['uid' => $item['uid']]);
if (!empty($user['language'])) {
return $user['language'];
}
}
// And finally just use the system language
return Config::get('system', 'language');
}
/** /**
* Creates an an "add tag" entry * Creates an an "add tag" entry
* *