]> git.mxchange.org Git - friendica.git/blobdiff - src/Content/OEmbed.php
Update function
[friendica.git] / src / Content / OEmbed.php
index 4aaae4d5dca37effc185eeee2c6cb5b0117e7d92..07c36685c3516f3afeb969e124d704bd8df37d02 100644 (file)
@@ -15,6 +15,7 @@ use dba;
 use DOMDocument;\r
 use DOMXPath;\r
 use DOMNode;\r
+use Exception;\r
 \r
 require_once 'include/dba.php';\r
 require_once 'mod/proxy.php';\r
@@ -298,11 +299,39 @@ class OEmbed
                }\r
 \r
                $domain = parse_url($url, PHP_URL_HOST);\r
+               if (!x($domain)) {\r
+                       return false;\r
+               }\r
 \r
                $str_allowed = Config::get('system', 'allowed_oembed', '');\r
+               if (!x($str_allowed)) {\r
+                       return false;\r
+               }\r
+               \r
                $allowed = explode(',', $str_allowed);\r
 \r
-               return allowed_domain($domain, $allowed, true);\r
+               return allowed_domain($domain, $allowed);\r
+       }\r
+\r
+       public static function getHTML($url, $title = null)\r
+       {\r
+               // Always embed the SSL version\r
+               $url = str_replace(array("http://www.youtube.com/", "http://player.vimeo.com/"),\r
+                                       array("https://www.youtube.com/", "https://player.vimeo.com/"), $url);\r
+\r
+               $o = OEmbed::fetchURL($url);\r
+\r
+               if (!is_object($o) || $o->type == 'error') {\r
+                       throw new Exception('OEmbed failed for URL: ' . $url);\r
+               }\r
+\r
+               if (x($title)) {\r
+                       $o->title = $title;\r
+               }\r
+\r
+               $html = OEmbed::formatObject($o);\r
+\r
+               return $html;\r
        }\r
 \r
        /**\r