X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FContent%2FOEmbed.php;h=0093ba11af38a8e948ab6cca40d5b0c59be0cf40;hb=0615c8438abf3519156d2ba9c0bf378c08f44737;hp=116120ab552474c4dfe3e8132ea995bb76716293;hpb=71ec84f6dc83f753fe80170cfdfd32d202850d90;p=friendica.git
diff --git a/src/Content/OEmbed.php b/src/Content/OEmbed.php
index 116120ab55..0093ba11af 100644
--- a/src/Content/OEmbed.php
+++ b/src/Content/OEmbed.php
@@ -10,18 +10,18 @@ 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;
use Friendica\Database\DBA;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
use Friendica\Util\ParseUrl;
use Friendica\Util\Proxy as ProxyUtils;
-
-require_once 'include/dba.php';
+use Friendica\Util\Strings;
/**
* Handles all OEmbed content fetching and replacement
@@ -51,16 +51,17 @@ 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;
- $condition = ['url' => normalise_link($embedurl), 'maxwidth' => $a->videowidth];
+ $condition = ['url' => Strings::normaliseLink($embedurl), 'maxwidth' => $a->videowidth];
$oembed_record = DBA::selectFirst('oembed', ['content'], $condition);
if (DBA::isResult($oembed_record)) {
$json_string = $oembed_record['content'];
@@ -115,14 +116,14 @@ class OEmbed
if (!empty($oembed->type) && $oembed->type != 'error') {
DBA::insert('oembed', [
- 'url' => normalise_link($embedurl),
+ 'url' => Strings::normaliseLink($embedurl),
'maxwidth' => $a->videowidth,
'content' => $json_string,
'created' => DateTimeFormat::utcNow()
], true);
- $cache_ttl = CACHE_DAY;
+ $cache_ttl = Cache::DAY;
} else {
- $cache_ttl = CACHE_FIVE_MINUTES;
+ $cache_ttl = Cache::FIVE_MINUTES;
}
Cache::set($cache_key, $json_string, $cache_ttl);
@@ -159,7 +160,7 @@ class OEmbed
}
}
- Addon::callHooks('oembed_fetch_url', $embedurl, $oembed);
+ Hook::callAll('oembed_fetch_url', $embedurl, $oembed);
return $oembed;
}
@@ -178,8 +179,8 @@ class OEmbed
$th = 120;
$tw = $th * $tr;
- $tpl = get_markup_template('oembed_video.tpl');
- $ret .= replace_macros($tpl, [
+ $tpl = Renderer::getMarkupTemplate('oembed_video.tpl');
+ $ret .= Renderer::replaceMacros($tpl, [
'$baseurl' => System::baseUrl(),
'$embedurl' => $oembed->embed_url,
'$escapedhtml' => base64_encode($oembed->html),
@@ -245,8 +246,7 @@ class OEmbed
$ret .= '';
- $ret = str_replace("\n", "", $ret);
- return mb_convert_encoding($ret, 'HTML-ENTITIES', mb_detect_encoding($ret));
+ return str_replace("\n", "", $ret);
}
public static function BBCode2HTML($text)
@@ -261,6 +261,9 @@ class OEmbed
/**
* Find ....
* and replace it with [embed]url[/embed]
+ *
+ * @param $text
+ * @return string
*/
public static function HTML2BBCode($text)
{
@@ -299,6 +302,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)
{
@@ -307,12 +311,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;
}
@@ -333,7 +337,7 @@ class OEmbed
throw new Exception('OEmbed failed for URL: ' . $url);
}
- if (x($title)) {
+ if (!empty($title)) {
$o->title = $title;
}
@@ -354,25 +358,24 @@ 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';
}
$width = '100%';
- $src = System::baseUrl() . '/oembed/' . base64url_encode($src);
+ $src = System::baseUrl() . '/oembed/' . Strings::base64UrlEncode($src);
return '';
}