]> git.mxchange.org Git - friendica.git/blobdiff - src/Content/OEmbed.php
Force invite remaining variable to be integer in Content\Widget
[friendica.git] / src / Content / OEmbed.php
index c37e36f6073c05d5560c4b1b1c44286deedffed7..94e95e5f51d234e04b3be242159c4b68cc894158 100644 (file)
@@ -10,9 +10,9 @@ use DOMNode;
 use DOMText;
 use DOMXPath;
 use Exception;
-use Friendica\Core\Addon;
 use Friendica\Core\Cache;
 use Friendica\Core\Config;
+use Friendica\Core\Hook;
 use Friendica\Core\L10n;
 use Friendica\Core\Renderer;
 use Friendica\Core\System;
@@ -23,8 +23,6 @@ use Friendica\Util\ParseUrl;
 use Friendica\Util\Proxy as ProxyUtils;
 use Friendica\Util\Strings;
 
-require_once 'include/dba.php';
-
 /**
  * Handles all OEmbed content fetching and replacement
  *
@@ -53,12 +51,13 @@ class OEmbed
         * @param bool   $no_rich_type If set to true rich type content won't be fetched.
         *
         * @return \Friendica\Object\OEmbed
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
        public static function fetchURL($embedurl, $no_rich_type = false)
        {
                $embedurl = trim($embedurl, '\'"');
 
-               $a = get_app();
+               $a = \get_app();
 
                $cache_key = 'oembed:' . $a->videowidth . ':' . $embedurl;
 
@@ -84,8 +83,7 @@ class OEmbed
 
                        if (!in_array($ext, $noexts)) {
                                // try oembed autodiscovery
-                               $redirects = 0;
-                               $html_text = Network::fetchUrl($embedurl, false, $redirects, 15, 'text/*');
+                               $html_text = Network::fetchUrl($embedurl, false, 15, 'text/*');
                                if ($html_text) {
                                        $dom = @DOMDocument::loadHTML($html_text);
                                        if ($dom) {
@@ -161,7 +159,7 @@ class OEmbed
                        }
                }
 
-               Addon::callHooks('oembed_fetch_url', $embedurl, $oembed);
+               Hook::callAll('oembed_fetch_url', $embedurl, $oembed);
 
                return $oembed;
        }
@@ -182,7 +180,6 @@ class OEmbed
                                        $tw = $th * $tr;
                                        $tpl = Renderer::getMarkupTemplate('oembed_video.tpl');
                                        $ret .= Renderer::replaceMacros($tpl, [
-                                               '$baseurl' => System::baseUrl(),
                                                '$embedurl' => $oembed->embed_url,
                                                '$escapedhtml' => base64_encode($oembed->html),
                                                '$tw' => $tw,
@@ -262,6 +259,9 @@ class OEmbed
        /**
         * Find <span class='oembed'>..<a href='url' rel='oembed'>..</a></span>
         * and replace it with [embed]url[/embed]
+        *
+        * @param $text
+        * @return string
         */
        public static function HTML2BBCode($text)
        {
@@ -300,6 +300,7 @@ class OEmbed
         * @brief Determines if rich content OEmbed is allowed for the provided URL
         * @param string $url
         * @return boolean
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
        public static function isAllowedURL($url)
        {
@@ -308,12 +309,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;
                }
 
@@ -334,7 +335,7 @@ class OEmbed
                        throw new Exception('OEmbed failed for URL: ' . $url);
                }
 
-               if (x($title)) {
+               if (!empty($title)) {
                        $o->title = $title;
                }
 
@@ -355,19 +356,18 @@ class OEmbed
         * Since the iframe is automatically resized on load, there are no need for ugly
         * and impractical scrollbars.
         *
-        * @todo This function is currently unused until someoneā„¢ adds support for a separate OEmbed domain
+        * @todo  This function is currently unused until someoneā„¢ adds support for a separate OEmbed domain
         *
         * @param string $src Original remote URL to embed
         * @param string $width
         * @param string $height
         * @return string formatted HTML
         *
-        * @see oembed_format_object()
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        * @see   oembed_format_object()
         */
        private static function iframe($src, $width, $height)
        {
-               $a = get_app();
-
                if (!$height || strstr($height, '%')) {
                        $height = '200';
                }