public static function replaceCallback($matches)
{
$embedurl = $matches[1];
- $j = self::fetchURL($embedurl);
+ $j = self::fetchURL($embedurl, !self::isAllowedURL($embedurl));
$s = self::formatObject($j);
return $s;
// 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);
// 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;
// If fetching information doesn't work, then improve via internal functions
- if (($j->type == "error") || ($no_rich_type && ($j->type == "rich"))) {
+ if ($no_rich_type && ($j->type == "rich")) {
$data = ParseUrl::getSiteinfoCached($embedurl, true, false);
$j->type = $data["type"];
if ($j->type == "photo") {
$j->url = $data["url"];
- //$j->width = $data["images"][0]["width"];
- //$j->height = $data["images"][0]["height"];
}
if (isset($data["title"])) {
return $j;
}
- public static function formatObject($j)
+ private static function formatObject($j)
{
$embedurl = $j->embedurl;
$jhtml = $j->html;
$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;
}
case "link":
break;
case "rich":
- if (self::isAllowedURL($embedurl)) {
- $ret .= proxy_parse_html($jhtml);
- }
+ $ret .= proxy_parse_html($jhtml);
break;
}
- $ret .= '</div>';
// 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 .= ": ";
}
}
$ret .= '<a href="' . $embedurl . '" rel="oembed">' . $embedlink . '</a>';
+ } else {
+ $ret .= '<a href="' . $embedurl . '" rel="oembed">' . $embedurl . '</a>';
}
$ret .= "</h4>";
} elseif (!strpos($j->html, $embedurl)) {
$ret .= '<a href="' . $embedurl . '" rel="oembed">' . $j->title . '</a>';
}
+ $ret .= '</div>';
+
$ret = str_replace("\n", "", $ret);
return mb_convert_encoding($ret, 'HTML-ENTITIES', mb_detect_encoding($ret));
}
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 = OEmbed::fetchURL($url);
+ $o = self::fetchURL($url, !self::isAllowedURL($url));
if (!is_object($o) || $o->type == 'error') {
throw new Exception('OEmbed failed for URL: ' . $url);
$o->title = $title;
}
- $html = OEmbed::formatObject($o);
+ $html = self::formatObject($o);
return $html;
}