forked from GNUsocial/gnu-social
[Embed][ENTITY] Fix embed route and use attachment_view rather than _show. Rename Entity::have to Entity::has, because grammar
This commit is contained in:
parent
30107de079
commit
b1e514832b
@ -94,10 +94,10 @@ class Embed extends Plugin
|
|||||||
/**
|
/**
|
||||||
* Insert oembed and opengraph tags in all HTML head elements
|
* Insert oembed and opengraph tags in all HTML head elements
|
||||||
*/
|
*/
|
||||||
public function onShowHeadElements(Request $request, array $result)
|
public function onShowHeadElements(Request $request, array &$result)
|
||||||
{
|
{
|
||||||
$matches = [];
|
$matches = [];
|
||||||
preg_match(',/?([^/]+)/?.*,', $request->getPathInfo(), $matches);
|
preg_match(',/?([^/]+)/?(.*),', $request->getPathInfo(), $matches);
|
||||||
switch ($matches[1]) {
|
switch ($matches[1]) {
|
||||||
case 'attachment':
|
case 'attachment':
|
||||||
$url = "{$matches[1]}/{$matches[2]}";
|
$url = "{$matches[1]}/{$matches[2]}";
|
||||||
@ -137,15 +137,18 @@ class Embed extends Plugin
|
|||||||
return Event::next;
|
return Event::next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_null($attachment->getRemoteUrl()) || (!is_null($mimetype = $attachment->getMimetype()) && (('text/html' === substr($mimetype, 0, 9) || 'application/xhtml+xml' === substr($mimetype, 0, 21))))) {
|
if ($attachment->hasRemoteUrl() && $attachment->hasMimetype()) {
|
||||||
try {
|
$mimetype = $attachment->getMimetype();
|
||||||
$embed_data = $this->getEmbed($attachment->getRemoteUrl(), $attachment);
|
if (Formatting::startsWith($mimetype, 'text/html') || Formatting::startsWith($mimetype, 'application/xhtml+xml')) {
|
||||||
$embed_data['attachment_id'] = $attachment->getId();
|
try {
|
||||||
DB::persist(Entity\AttachmentEmbed::create($embed_data));
|
$embed_data = $this->getEmbed($attachment->getRemoteUrl(), $attachment);
|
||||||
DB::flush();
|
$embed_data['attachment_id'] = $attachment->getId();
|
||||||
} catch (Exception $e) {
|
DB::persist(Entity\AttachmentEmbed::create($embed_data));
|
||||||
Log::warning($e);
|
DB::flush();
|
||||||
return Event::next;
|
} catch (Exception $e) {
|
||||||
|
Log::warning($e);
|
||||||
|
return Event::next;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Event::next;
|
return Event::next;
|
||||||
@ -355,7 +358,7 @@ END, ['embed' => $embed, 'attributes' => $attributes]);
|
|||||||
*/
|
*/
|
||||||
protected function storeRemoteThumbnail(Attachment $attachment): array | bool
|
protected function storeRemoteThumbnail(Attachment $attachment): array | bool
|
||||||
{
|
{
|
||||||
if ($attachment->haveFilename() && file_exists($attachment->getPath())) {
|
if ($attachment->hasFilename() && file_exists($attachment->getPath())) {
|
||||||
throw new AlreadyFulfilledException(_m('A thumbnail seems to already exist for remote file with id=={id}', ['id' => $attachment->getId()]));
|
throw new AlreadyFulfilledException(_m('A thumbnail seems to already exist for remote file with id=={id}', ['id' => $attachment->getId()]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,7 +209,7 @@ class AttachmentEmbed extends Entity
|
|||||||
|
|
||||||
public function getAttachmentUrl()
|
public function getAttachmentUrl()
|
||||||
{
|
{
|
||||||
return Router::url('attachment_show', ['id' => $this->getAttachmentId()]);
|
return Router::url('attachment_view', ['id' => $this->getAttachmentId()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isImage()
|
public function isImage()
|
||||||
|
@ -33,8 +33,8 @@ abstract class Entity
|
|||||||
{
|
{
|
||||||
public function __call(string $name , array $arguments): mixed
|
public function __call(string $name , array $arguments): mixed
|
||||||
{
|
{
|
||||||
if (Formatting::startsWith($name, 'have')) {
|
if (Formatting::startsWith($name, 'has')) {
|
||||||
$prop = Formatting::camelCaseToSnakeCase(Formatting::removePrefix($name, 'have'));
|
$prop = Formatting::camelCaseToSnakeCase(Formatting::removePrefix($name, 'has'));
|
||||||
return isset($this->{$prop});
|
return isset($this->{$prop});
|
||||||
}
|
}
|
||||||
throw new \Exception("Entity::{$name} called with bogus arguments: " . print_r($arguments, true));
|
throw new \Exception("Entity::{$name} called with bogus arguments: " . print_r($arguments, true));
|
||||||
|
Loading…
Reference in New Issue
Block a user