/**
* @file src/Content/OEmbed.php
*/
-
namespace Friendica\Content;
+use Friendica\Core\Addon;
use Friendica\Core\Cache;
-use Friendica\Core\System;
use Friendica\Core\Config;
+use Friendica\Core\L10n;
+use Friendica\Core\System;
use Friendica\Database\DBM;
+use Friendica\Util\DateTimeFormat;
+use Friendica\Util\Network;
use Friendica\Util\ParseUrl;
use dba;
use DOMDocument;
-use DOMXPath;
use DOMNode;
+use DOMText;
+use DOMXPath;
use Exception;
require_once 'include/dba.php';
// 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);
if (!in_array($ext, $noexts)) {
// try oembed autodiscovery
$redirects = 0;
- $html_text = fetch_url($embedurl, false, $redirects, 15, "text/*");
+ $html_text = Network::fetchUrl($embedurl, false, $redirects, 15, "text/*");
if ($html_text) {
$dom = @DOMDocument::loadHTML($html_text);
if ($dom) {
$entries = $xpath->query("//link[@type='application/json+oembed']");
foreach ($entries as $e) {
$href = $e->getAttributeNode("href")->nodeValue;
- $txt = fetch_url($href . '&maxwidth=' . $a->videowidth);
+ $txt = Network::fetchUrl($href . '&maxwidth=' . $a->videowidth);
break;
}
$entries = $xpath->query("//link[@type='text/json+oembed']");
foreach ($entries as $e) {
$href = $e->getAttributeNode("href")->nodeValue;
- $txt = fetch_url($href . '&maxwidth=' . $a->videowidth);
+ $txt = Network::fetchUrl($href . '&maxwidth=' . $a->videowidth);
break;
}
}
'url' => normalise_link($embedurl),
'maxwidth' => $a->videowidth,
'content' => $txt,
- 'created' => datetime_convert()
+ 'created' => DateTimeFormat::utcNow()
], true);
}
// 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;
}
}
- call_hooks('oembed_fetch_url', $embedurl, $j);
+ Addon::callHooks('oembed_fetch_url', $embedurl, $j);
return $j;
}
$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;
}
{
$stopoembed = Config::get("system", "no_oembed");
if ($stopoembed == true) {
- return preg_replace("/\[embed\](.+?)\[\/embed\]/is", "<!-- oembed $1 --><i>" . t('Embedding disabled') . " : $1</i><!-- /oembed $1 -->", $text);
+ return preg_replace("/\[embed\](.+?)\[\/embed\]/is", "<!-- oembed $1 --><i>" . L10n::t('Embedding disabled') . " : $1</i><!-- /oembed $1 -->", $text);
}
return preg_replace_callback("/\[embed\](.+?)\[\/embed\]/is", ['self', 'replaceCallback'], $text);
}
$allowed = explode(',', $str_allowed);
- return allowed_domain($domain, $allowed);
+ return Network::isDomainAllowed($domain, $allowed);
}
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));
$width = '100%';
$src = System::baseUrl() . '/oembed/' . base64url_encode($src);
- return '<iframe onload="resizeIframe(this);" class="embed_rich" height="' . $height . '" width="' . $width . '" src="' . $src . '" allowfullscreen scrolling="no" frameborder="no">' . t('Embedded content') . '</iframe>';
+ return '<iframe onload="resizeIframe(this);" class="embed_rich" height="' . $height . '" width="' . $width . '" src="' . $src . '" allowfullscreen scrolling="no" frameborder="no">' . L10n::t('Embedded content') . '</iframe>';
}
/**