]> git.mxchange.org Git - friendica.git/commitdiff
Replace hacky oembed local iframe with remote iframe html
authorHypolite Petovan <mrpetovan@gmail.com>
Sat, 6 Jan 2018 05:35:43 +0000 (00:35 -0500)
committerHypolite Petovan <mrpetovan@gmail.com>
Sat, 6 Jan 2018 05:35:43 +0000 (00:35 -0500)
- Remove call to OEmbed::iframe
- Replace oembed span by div
- Replace double quotes with single

src/Content/OEmbed.php

index c317483d96d8149709900df37a7c94f9dfb43c48..0095d2b3cb33db58d50220322a3f5b63a34996ee 100644 (file)
@@ -160,8 +160,8 @@ class OEmbed
        public static function formatObject($j)\r
        {\r
                $embedurl = $j->embedurl;\r
-               $jhtml = self::iframe($j->embedurl, (isset($j->width) ? $j->width : null), (isset($j->height) ? $j->height : null));\r
-               $ret = "<span class='oembed " . $j->type . "'>";\r
+               $jhtml = $j->html;\r
+               $ret = '<div class="oembed ' . $j->type . '">';\r
                switch ($j->type) {\r
                        case "video":\r
                                if (isset($j->thumbnail_url)) {\r
@@ -173,7 +173,7 @@ class OEmbed
                                        $th = 120;\r
                                        $tw = $th * $tr;\r
                                        $tpl = get_markup_template('oembed_video.tpl');\r
-                                       $ret.=replace_macros($tpl, array(\r
+                                       $ret .= replace_macros($tpl, array(\r
                                                '$baseurl' => System::baseUrl(),\r
                                                '$embedurl' => $embedurl,\r
                                                '$escapedhtml' => base64_encode($jhtml),\r
@@ -184,33 +184,32 @@ class OEmbed
                                } else {\r
                                        $ret = $jhtml;\r
                                }\r
-                               //$ret.="<br>";\r
                                break;\r
                        case "photo":\r
-                               $ret.= "<img width='" . $j->width . "' src='" . proxy_url($j->url) . "'>";\r
+                               $ret .= '<img width="' . $j->width . '" src="' . proxy_url($j->url) . '">';\r
                                break;\r
                        case "link":\r
                                break;\r
                        case "rich":\r
-                               // not so safe..\r
                                if (self::isAllowedURL($embedurl)) {\r
                                        $ret .= proxy_parse_html($jhtml);\r
                                }\r
                                break;\r
                }\r
 \r
+               $ret .= '</div>';\r
                // add link to source if not present in "rich" type\r
                if ($j->type != 'rich' || !strpos($j->html, $embedurl)) {\r
-                       $ret .= "<h4>";\r
+                       $ret .= '<h4>';\r
                        if (isset($j->title)) {\r
                                if (isset($j->provider_name)) {\r
                                        $ret .= $j->provider_name . ": ";\r
                                }\r
 \r
                                $embedlink = (isset($j->title)) ? $j->title : $embedurl;\r
-                               $ret .= "<a href='$embedurl' rel='oembed'>$embedlink</a>";\r
+                               $ret .= '<a href="' . $embedurl . '" rel="oembed">' . $embedlink . '</a>';\r
                                if (isset($j->author_name)) {\r
-                                       $ret.=" (" . $j->author_name . ")";\r
+                                       $ret .= ' (' . $j->author_name . ')';\r
                                }\r
                        } elseif (isset($j->provider_name) || isset($j->author_name)) {\r
                                $embedlink = "";\r
@@ -229,16 +228,14 @@ class OEmbed
                                        $embedlink = $embedurl;\r
                                }\r
 \r
-                               $ret .= "<a href='$embedurl' rel='oembed'>$embedlink</a>";\r
+                               $ret .= '<a href="' . $embedurl . '" rel="oembed">' . $embedlink . '</a>';\r
                        }\r
-                       //if (isset($j->author_name)) $ret.=" by ".$j->author_name;\r
-                       //if (isset($j->provider_name)) $ret.=" on ".$j->provider_name;\r
                        $ret .= "</h4>";\r
-               } else {\r
+               } elseif (!strpos($j->html, $embedurl)) {\r
                        // add <a> for html2bbcode conversion\r
-                       $ret .= "<a href='$embedurl' rel='oembed'>$embedurl</a>";\r
+                       $ret .= '<a href="' . $embedurl . '" rel="oembed">' . $j->title . '</a>';\r
                }\r
-               $ret.="</span>";\r
+\r
                $ret = str_replace("\n", "", $ret);\r
                return mb_convert_encoding($ret, 'HTML-ENTITIES', mb_detect_encoding($ret));\r
        }\r
@@ -272,7 +269,7 @@ class OEmbed
                        $xpath = new DOMXPath($dom);\r
 \r
                        $xattr = self::buildXPath("class", "oembed");\r
-                       $entries = $xpath->query("//span[$xattr]");\r
+                       $entries = $xpath->query("//div[$xattr]");\r
 \r
                        $xattr = "@rel='oembed'"; //oe_build_xpath("rel","oembed");\r
                        foreach ($entries as $e) {\r
@@ -299,6 +296,8 @@ class OEmbed
         * Since the iframe is automatically resized on load, there are no need for ugly\r
         * and impractical scrollbars.\r
         *\r
+        * @todo This function is currently unused until someoneā„¢ adds support for a separate OEmbed domain\r
+        *\r
         * @param string $src Original remote URL to embed\r
         * @param string $width\r
         * @param string $height\r
@@ -315,10 +314,7 @@ class OEmbed
                }\r
                $width = '100%';\r
 \r
-               // Only proxy OEmbed URLs to avoid mixed-content errors\r
-               if (Config::get('system', 'ssl_policy') == SSL_POLICY_FULL && parse_url($src, PHP_URL_SCHEME) !== 'https') {\r
-                       $src = System::baseUrl() . '/oembed/' . base64url_encode($src);\r
-               }\r
+               $src = System::baseUrl() . '/oembed/' . base64url_encode($src);\r
                return '<iframe onload="resizeIframe(this);" class="embed_rich" height="' . $height . '" width="' . $width . '" src="' . $src . '" allowfullscreen scrolling="no" frameborder="no">' . t('Embedded content') . '</iframe>';\r
        }\r
 \r