1
0
mirror of https://github.com/owncloud/bookmarks.git synced 2025-03-10 10:29:20 +01:00

Improve encoding detection

This commit is contained in:
Arthur Schiwon 2016-04-24 21:01:44 +02:00
parent 5535cbbfb5
commit 1dc98e7067
No known key found for this signature in database
GPG Key ID: 7424F1874854DF23

View File

@ -553,7 +553,9 @@ class Bookmarks {
$page = "";
try {
$page = \OC::$server->getHTTPHelper()->getUrlContent($url);
$request = \OC::$server->getHTTPClientService()->newClient()->get($url);
$page = $request->getBody();
$contentType = $request->getHeader('Content-Type');
} catch (\Exception $e) {
throw $e;
}
@ -561,7 +563,10 @@ class Bookmarks {
//Check for encoding of site.
//If not UTF-8 convert it.
$encoding = array();
preg_match('/charset="?(.*?)["|;]/i', $page, $encoding);
preg_match('#.+?/.+?;\\s?charset\\s?=\\s?(.+)#i', $contentType, $encoding);
if(empty($encoding)) {
preg_match('/charset="?(.*?)["|;]/i', $page, $encoding);
}
if (isset($encoding[1])) {
$decodeFrom = strtoupper($encoding[1]);