Fix default oembed styles for twitter posts (#6581)

This commit is contained in:
Yuriy Bakhtin 2023-09-20 18:37:03 +02:00 committed by GitHub
parent 137b8fb6f9
commit f29a1e4cdf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 28 deletions

View File

@ -28,6 +28,7 @@ HumHub Changelog
- Fix #6558: Avoid PHP 8.1+ deprecated null parameter on preg_replace in richtext converters
- Fix #6544: Registration not possible with SSO and email invites if "New users can register" is disabled
- Fix #6572: Posts count in space should be only for published content
- Fix #3755: Fix default oembed styles for twitter posts
1.15.0-beta.1 (July 31, 2023)
-----------------------------

View File

@ -115,14 +115,14 @@ class UrlOembed extends ActiveRecord
*
* @return string|null
*/
public function getProviderUrl()
public function getProviderUrl(): ?string
{
foreach (static::getProviders() as $provider) {
if (isset($provider['pattern']) && preg_match($provider['pattern'], $this->url)) {
return str_replace("%url%", urlencode($this->url), $provider['endpoint']);
}
$provider = static::getProviderByUrl($this->url);
if ($provider === null) {
return null;
}
return null;
return str_replace("%url%", urlencode($this->url), $provider['endpoint']);
}
/**
@ -292,7 +292,7 @@ class UrlOembed extends ActiveRecord
'data' => [
'guid' => uniqid('oembed-', true),
'richtext-feature' => 1,
'oembed-provider' => Html::encode(static::getProviderByUrl($url)),
'oembed-provider' => Html::encode(static::getProviderOptionByUrl($url, 'endpoint')),
'url' => Html::encode($url)
],
'class' => 'oembed_snippet',
@ -350,26 +350,46 @@ class UrlOembed extends ActiveRecord
* @param string $url
* @return boolean
*/
public static function hasOEmbedSupport($url)
public static function hasOEmbedSupport(string $url): bool
{
return static::getProviderByUrl($url) != null;
return static::getProviderByUrl($url) !== null;
}
/**
* @param $url
* @return mixed|null
* Find provider by pattern with provided URL
*
* @param string $url
* @return array|null
*/
public static function getProviderByUrl($url)
public static function getProviderByUrl(string $url): ?array
{
foreach (static::getProviders() as $provider) {
foreach (static::getProviders() as $name => $provider) {
if (isset($provider['pattern']) && preg_match($provider['pattern'], $url)) {
return $provider['endpoint'];
$provider['name'] = $name;
return $provider;
}
}
return null;
}
/**
* Get provider option by URL
*
* @param string $url
* @param string $option 'name', 'pattern', 'endpoint'
* @return array|null
*/
public static function getProviderOptionByUrl(string $url, string $option = 'name'): ?string
{
$provider = static::getProviderByUrl($url);
if ($provider === null) {
return null;
}
return $provider[$option] ?? null;
}
/**
* Executes the remote fetch call in case the [$maxUrlFetchLimit] is not reached.
*

View File

@ -1,24 +1,24 @@
.oembed_snippet[data-oembed-provider="youtube.com"],
.oembed_snippet {
margin-top: 10px;
position: relative;
padding-bottom: 55%;
padding-top: 15px;
overflow: hidden;
}
.oembed_snippet[data-oembed-provider="twitter.com"] {
padding-bottom: 0 !important;
padding-top: 0;
margin-top: 0;
}
&[data-oembed-provider="Twitter"],
&[data-oembed-provider*="twitter.com"] {
padding-bottom: 0 !important;
padding-top: 0;
margin-top: 0;
}
.oembed_snippet iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
}
.oembed_confirmation {

File diff suppressed because one or more lines are too long