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
|
||||
*/
|
||||
public function onShowHeadElements(Request $request, array $result)
|
||||
public function onShowHeadElements(Request $request, array &$result)
|
||||
{
|
||||
$matches = [];
|
||||
preg_match(',/?([^/]+)/?.*,', $request->getPathInfo(), $matches);
|
||||
preg_match(',/?([^/]+)/?(.*),', $request->getPathInfo(), $matches);
|
||||
switch ($matches[1]) {
|
||||
case 'attachment':
|
||||
$url = "{$matches[1]}/{$matches[2]}";
|
||||
@ -137,15 +137,18 @@ class Embed extends Plugin
|
||||
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))))) {
|
||||
try {
|
||||
$embed_data = $this->getEmbed($attachment->getRemoteUrl(), $attachment);
|
||||
$embed_data['attachment_id'] = $attachment->getId();
|
||||
DB::persist(Entity\AttachmentEmbed::create($embed_data));
|
||||
DB::flush();
|
||||
} catch (Exception $e) {
|
||||
Log::warning($e);
|
||||
return Event::next;
|
||||
if ($attachment->hasRemoteUrl() && $attachment->hasMimetype()) {
|
||||
$mimetype = $attachment->getMimetype();
|
||||
if (Formatting::startsWith($mimetype, 'text/html') || Formatting::startsWith($mimetype, 'application/xhtml+xml')) {
|
||||
try {
|
||||
$embed_data = $this->getEmbed($attachment->getRemoteUrl(), $attachment);
|
||||
$embed_data['attachment_id'] = $attachment->getId();
|
||||
DB::persist(Entity\AttachmentEmbed::create($embed_data));
|
||||
DB::flush();
|
||||
} catch (Exception $e) {
|
||||
Log::warning($e);
|
||||
return Event::next;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Event::next;
|
||||
@ -355,7 +358,7 @@ END, ['embed' => $embed, 'attributes' => $attributes]);
|
||||
*/
|
||||
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()]));
|
||||
}
|
||||
|
||||
|
@ -209,7 +209,7 @@ class AttachmentEmbed extends Entity
|
||||
|
||||
public function getAttachmentUrl()
|
||||
{
|
||||
return Router::url('attachment_show', ['id' => $this->getAttachmentId()]);
|
||||
return Router::url('attachment_view', ['id' => $this->getAttachmentId()]);
|
||||
}
|
||||
|
||||
public function isImage()
|
||||
|
@ -33,8 +33,8 @@ abstract class Entity
|
||||
{
|
||||
public function __call(string $name , array $arguments): mixed
|
||||
{
|
||||
if (Formatting::startsWith($name, 'have')) {
|
||||
$prop = Formatting::camelCaseToSnakeCase(Formatting::removePrefix($name, 'have'));
|
||||
if (Formatting::startsWith($name, 'has')) {
|
||||
$prop = Formatting::camelCaseToSnakeCase(Formatting::removePrefix($name, 'has'));
|
||||
return isset($this->{$prop});
|
||||
}
|
||||
throw new \Exception("Entity::{$name} called with bogus arguments: " . print_r($arguments, true));
|
||||
|
Loading…
Reference in New Issue
Block a user