]> git.mxchange.org Git - friendica.git/blobdiff - src/Content/OEmbed.php
Fix undefined offset notices in Protocol\Email
[friendica.git] / src / Content / OEmbed.php
index cfe9468ad57a58a0f893b0fb9d16522aa59e60fc..6aa76a55ac124af15540286e26b2a7be1b0efe67 100644 (file)
@@ -14,14 +14,14 @@ use Friendica\Core\Addon;
 use Friendica\Core\Cache;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
+use Friendica\Core\Renderer;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
 use Friendica\Util\ParseUrl;
 use Friendica\Util\Proxy as ProxyUtils;
-
-require_once 'include/dba.php';
+use Friendica\Util\Strings;
 
 /**
  * Handles all OEmbed content fetching and replacement
@@ -56,11 +56,11 @@ class OEmbed
        {
                $embedurl = trim($embedurl, '\'"');
 
-               $a = get_app();
+               $a = \get_app();
 
                $cache_key = 'oembed:' . $a->videowidth . ':' . $embedurl;
 
-               $condition = ['url' => normalise_link($embedurl), 'maxwidth' => $a->videowidth];
+               $condition = ['url' => Strings::normaliseLink($embedurl), 'maxwidth' => $a->videowidth];
                $oembed_record = DBA::selectFirst('oembed', ['content'], $condition);
                if (DBA::isResult($oembed_record)) {
                        $json_string = $oembed_record['content'];
@@ -115,7 +115,7 @@ class OEmbed
 
                        if (!empty($oembed->type) && $oembed->type != 'error') {
                                DBA::insert('oembed', [
-                                       'url' => normalise_link($embedurl),
+                                       'url' => Strings::normaliseLink($embedurl),
                                        'maxwidth' => $a->videowidth,
                                        'content' => $json_string,
                                        'created' => DateTimeFormat::utcNow()
@@ -178,8 +178,8 @@ class OEmbed
 
                                        $th = 120;
                                        $tw = $th * $tr;
-                                       $tpl = get_markup_template('oembed_video.tpl');
-                                       $ret .= replace_macros($tpl, [
+                                       $tpl = Renderer::getMarkupTemplate('oembed_video.tpl');
+                                       $ret .= Renderer::replaceMacros($tpl, [
                                                '$baseurl' => System::baseUrl(),
                                                '$embedurl' => $oembed->embed_url,
                                                '$escapedhtml' => base64_encode($oembed->html),
@@ -245,8 +245,7 @@ class OEmbed
 
                $ret .= '</div>';
 
-               $ret = str_replace("\n", "", $ret);
-               return mb_convert_encoding($ret, 'HTML-ENTITIES', mb_detect_encoding($ret));
+               return str_replace("\n", "", $ret);
        }
 
        public static function BBCode2HTML($text)
@@ -307,12 +306,12 @@ class OEmbed
                }
 
                $domain = parse_url($url, PHP_URL_HOST);
-               if (!x($domain)) {
+               if (empty($domain)) {
                        return false;
                }
 
                $str_allowed = Config::get('system', 'allowed_oembed', '');
-               if (!x($str_allowed)) {
+               if (empty($str_allowed)) {
                        return false;
                }
 
@@ -333,7 +332,7 @@ class OEmbed
                        throw new Exception('OEmbed failed for URL: ' . $url);
                }
 
-               if (x($title)) {
+               if (!empty($title)) {
                        $o->title = $title;
                }
 
@@ -365,14 +364,14 @@ class OEmbed
         */
        private static function iframe($src, $width, $height)
        {
-               $a = get_app();
+               $a = \get_app();
 
                if (!$height || strstr($height, '%')) {
                        $height = '200';
                }
                $width = '100%';
 
-               $src = System::baseUrl() . '/oembed/' . base64url_encode($src);
+               $src = System::baseUrl() . '/oembed/' . Strings::base64UrlEncode($src);
                return '<iframe onload="resizeIframe(this);" class="embed_rich" height="' . $height . '" width="' . $width . '" src="' . $src . '" allowfullscreen scrolling="no" frameborder="no">' . L10n::t('Embedded content') . '</iframe>';
        }