]> git.mxchange.org Git - friendica.git/blobdiff - src/Util/ParseUrl.php
Merge branch '2019.01-rc' into bug/6334-escape-get-app
[friendica.git] / src / Util / ParseUrl.php
index 6530959f234e64cac4205e09d2f6b5158117e831..70c5279cc84a42ce9314a202375cb2f1382c6fd5 100644 (file)
@@ -12,8 +12,7 @@ use Friendica\Core\Addon;
 use Friendica\Core\Logger;
 use Friendica\Database\DBA;
 use Friendica\Object\Image;
-
-require_once 'include/dba.php';
+use Friendica\Util\Strings;
 
 /**
  * @brief Class with methods for extracting certain content from an url
@@ -49,7 +48,7 @@ class ParseUrl
                }
 
                $parsed_url = DBA::selectFirst('parsed_url', ['content'],
-                       ['url' => normalise_link($url), 'guessing' => !$no_guessing, 'oembed' => $do_oembed]
+                       ['url' => Strings::normaliseLink($url), 'guessing' => !$no_guessing, 'oembed' => $do_oembed]
                );
                if (!empty($parsed_url['content'])) {
                        $data = unserialize($parsed_url['content']);
@@ -61,7 +60,7 @@ class ParseUrl
                DBA::insert(
                        'parsed_url',
                        [
-                               'url' => normalise_link($url), 'guessing' => !$no_guessing,
+                               'url' => Strings::normaliseLink($url), 'guessing' => !$no_guessing,
                                'oembed' => $do_oembed, 'content' => serialize($data),
                                'created' => DateTimeFormat::utcNow()
                        ],
@@ -112,7 +111,7 @@ class ParseUrl
         */
        public static function getSiteinfo($url, $no_guessing = false, $do_oembed = true, $count = 1)
        {
-               $a = get_app();
+               $a = \get_app();
 
                $siteinfo = [];
 
@@ -183,11 +182,10 @@ class ParseUrl
                        $charset = trim(trim(trim(array_pop($matches)), ';,'));
                }
 
-               if ($charset == '') {
-                       $charset = 'utf-8';
-               }
+               if ($charset && strtoupper($charset) != 'UTF-8') {
+                       // See https://github.com/friendica/friendica/issues/5470#issuecomment-418351211
+                       $charset = str_ireplace('latin-1', 'latin1', $charset);
 
-               if (($charset != '') && (strtoupper($charset) != 'UTF-8')) {
                        Logger::log('detected charset ' . $charset, Logger::DEBUG);
                        $body = iconv($charset, 'UTF-8//TRANSLIT', $body);
                }