]> git.mxchange.org Git - friendica.git/blobdiff - src/Content/OEmbed.php
Merge pull request #4243 from MrPetovan/task/switch-to-array-new-style
[friendica.git] / src / Content / OEmbed.php
index 836f5a2184efea783e7b41a80f97d2e0bff8cbd5..a8780d4d51e225349cede4a654a495c8f2f00c54 100644 (file)
@@ -67,7 +67,7 @@ class OEmbed
                // These media files should now be caught in bbcode.php
                // left here as a fallback in case this is called from another source
 
-               $noexts = array("mp3", "mp4", "ogg", "ogv", "oga", "ogm", "webm");
+               $noexts = ["mp3", "mp4", "ogg", "ogv", "oga", "ogm", "webm"];
                $ext = pathinfo(strtolower($embedurl), PATHINFO_EXTENSION);
 
 
@@ -125,7 +125,7 @@ class OEmbed
 
                // Always embed the SSL version
                if (isset($j->html)) {
-                       $j->html = str_replace(array("http://www.youtube.com/", "http://player.vimeo.com/"), array("https://www.youtube.com/", "https://player.vimeo.com/"), $j->html);
+                       $j->html = str_replace(["http://www.youtube.com/", "http://player.vimeo.com/"], ["https://www.youtube.com/", "https://player.vimeo.com/"], $j->html);
                }
 
                $j->embedurl = $embedurl;
@@ -175,14 +175,14 @@ class OEmbed
                                        $th = 120;
                                        $tw = $th * $tr;
                                        $tpl = get_markup_template('oembed_video.tpl');
-                                       $ret .= replace_macros($tpl, array(
+                                       $ret .= replace_macros($tpl, [
                                                '$baseurl' => System::baseUrl(),
                                                '$embedurl' => $embedurl,
                                                '$escapedhtml' => base64_encode($jhtml),
                                                '$tw' => $tw,
                                                '$th' => $th,
                                                '$turl' => $j->thumbnail_url,
-                                       ));
+                                       ]);
                                } else {
                                        $ret = $jhtml;
                                }
@@ -200,23 +200,22 @@ class OEmbed
                // add link to source if not present in "rich" type
                if ($j->type != 'rich' || !strpos($j->html, $embedurl)) {
                        $ret .= '<h4>';
-                       if (isset($j->title)) {
-                               if (isset($j->provider_name)) {
+                       if (!empty($j->title)) {
+                               if (!empty($j->provider_name)) {
                                        $ret .= $j->provider_name . ": ";
                                }
 
-                               $embedlink = (isset($j->title)) ? $j->title : $embedurl;
-                               $ret .= '<a href="' . $embedurl . '" rel="oembed">' . $embedlink . '</a>';
-                               if (isset($j->author_name)) {
+                               $ret .= '<a href="' . $embedurl . '" rel="oembed">' . $j->title . '</a>';
+                               if (!empty($j->author_name)) {
                                        $ret .= ' (' . $j->author_name . ')';
                                }
-                       } elseif (isset($j->provider_name) || isset($j->author_name)) {
+                       } elseif (!empty($j->provider_name) || !empty($j->author_name)) {
                                $embedlink = "";
-                               if (isset($j->provider_name)) {
+                               if (!empty($j->provider_name)) {
                                        $embedlink .= $j->provider_name;
                                }
 
-                               if (isset($j->author_name)) {
+                               if (!empty($j->author_name)) {
                                        if ($embedlink != "") {
                                                $embedlink .= ": ";
                                        }
@@ -228,6 +227,8 @@ class OEmbed
                                }
 
                                $ret .= '<a href="' . $embedurl . '" rel="oembed">' . $embedlink . '</a>';
+                       } else {
+                               $ret .= '<a href="' . $embedurl . '" rel="oembed">' . $embedurl . '</a>';
                        }
                        $ret .= "</h4>";
                } elseif (!strpos($j->html, $embedurl)) {
@@ -316,8 +317,8 @@ class OEmbed
        public static function getHTML($url, $title = null)
        {
                // Always embed the SSL version
-               $url = str_replace(array("http://www.youtube.com/", "http://player.vimeo.com/"),
-                                       array("https://www.youtube.com/", "https://player.vimeo.com/"), $url);
+               $url = str_replace(["http://www.youtube.com/", "http://player.vimeo.com/"],
+                                       ["https://www.youtube.com/", "https://player.vimeo.com/"], $url);
 
                $o = self::fetchURL($url, !self::isAllowedURL($url));