X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=application%2Ffront%2Fcontroller%2Fadmin%2FManageShaareController.php;h=df2f1631d001956e6b26b92a3298cbcd74b082fa;hb=4cf3564d28dc8e4d08a3e64f09ad045ffbde97ae;hp=3aa484239e71b62539157e20ba7b9f70b15e543c;hpb=1a8ac737e52cb25a5c346232ee398f5908cee7d7;p=github%2Fshaarli%2FShaarli.git diff --git a/application/front/controller/admin/ManageShaareController.php b/application/front/controller/admin/ManageShaareController.php index 3aa48423..df2f1631 100644 --- a/application/front/controller/admin/ManageShaareController.php +++ b/application/front/controller/admin/ManageShaareController.php @@ -53,38 +53,24 @@ class ManageShaareController extends ShaarliAdminController // If this is an HTTP(S) link, we try go get the page to extract // the title (otherwise we will to straight to the edit form.) - if (empty($title) && strpos(get_url_scheme($url) ?: '', 'http') !== false) { - $retrieveDescription = $this->container->conf->get('general.retrieve_description'); - // Short timeout to keep the application responsive - // The callback will fill $charset and $title with data from the downloaded page. - $this->container->httpAccess->getHttpResponse( - $url, - $this->container->conf->get('general.download_timeout', 30), - $this->container->conf->get('general.download_max_size', 4194304), - $this->container->httpAccess->getCurlDownloadCallback( - $charset, - $title, - $description, - $tags, - $retrieveDescription - ) - ); - if (! empty($title) && strtolower($charset) !== 'utf-8') { - $title = mb_convert_encoding($title, 'utf-8', $charset); - } + if (true !== $this->container->conf->get('general.enable_async_metadata', true) + && empty($title) + && strpos(get_url_scheme($url) ?: '', 'http') !== false + ) { + $metadata = $this->container->metadataRetriever->retrieve($url); } - if (empty($url) && empty($title)) { - $title = $this->container->conf->get('general.default_note_title', t('Note: ')); + if (empty($url)) { + $metadata['title'] = $this->container->conf->get('general.default_note_title', t('Note: ')); } - $link = escape([ - 'title' => $title, + $link = [ + 'title' => $title ?? $metadata['title'] ?? '', 'url' => $url ?? '', - 'description' => $description ?? '', - 'tags' => $tags ?? '', + 'description' => $description ?? $metadata['description'] ?? '', + 'tags' => $tags ?? $metadata['tags'] ?? '', 'private' => $private, - ]); + ]; } else { $formatter = $this->container->formatterFactory->getFormatter('raw'); $link = $formatter->format($bookmark); @@ -127,7 +113,7 @@ class ManageShaareController extends ShaarliAdminController $this->checkToken($request); // lf_id should only be present if the link exists. - $id = $request->getParam('lf_id') ? intval(escape($request->getParam('lf_id'))) : null; + $id = $request->getParam('lf_id') !== null ? intval(escape($request->getParam('lf_id'))) : null; if (null !== $id && true === $this->container->bookmarkService->exists($id)) { // Edit $bookmark = $this->container->bookmarkService->get($id); @@ -152,7 +138,7 @@ class ManageShaareController extends ShaarliAdminController // To preserve backward compatibility with 3rd parties, plugins still use arrays $formatter = $this->container->formatterFactory->getFormatter('raw'); $data = $formatter->format($bookmark); - $data = $this->executeHooks('save_link', $data); + $this->executePageHooks('save_link', $data); $bookmark->fromArray($data); $this->container->bookmarkService->set($bookmark); @@ -169,7 +155,7 @@ class ManageShaareController extends ShaarliAdminController return $this->redirectFromReferer( $request, $response, - ['add-shaare', 'shaare'], ['addlink', 'post', 'edit_link'], + ['/admin/add-shaare', '/admin/shaare'], ['addlink', 'post', 'edit_link'], $bookmark->getShortUrl() ); } @@ -211,7 +197,7 @@ class ManageShaareController extends ShaarliAdminController } $data = $formatter->format($bookmark); - $this->container->pluginManager->executeHooks('delete_link', $data); + $this->executePageHooks('delete_link', $data); $this->container->bookmarkService->remove($bookmark, false); ++ $count; } @@ -283,7 +269,7 @@ class ManageShaareController extends ShaarliAdminController // To preserve backward compatibility with 3rd parties, plugins still use arrays $data = $formatter->format($bookmark); - $this->container->pluginManager->executeHooks('save_link', $data); + $this->executePageHooks('save_link', $data); $bookmark->fromArray($data); $this->container->bookmarkService->set($bookmark, false); @@ -325,7 +311,7 @@ class ManageShaareController extends ShaarliAdminController // To preserve backward compatibility with 3rd parties, plugins still use arrays $data = $formatter->format($bookmark); - $this->container->pluginManager->executeHooks('save_link', $data); + $this->executePageHooks('save_link', $data); $bookmark->fromArray($data); $this->container->bookmarkService->set($bookmark); @@ -345,16 +331,18 @@ class ManageShaareController extends ShaarliAdminController $tags[BookmarkMarkdownFormatter::NO_MD_TAG] = 1; } - $data = [ + $data = escape([ 'link' => $link, 'link_is_new' => $isNew, - 'http_referer' => escape($this->container->environment['HTTP_REFERER'] ?? ''), + 'http_referer' => $this->container->environment['HTTP_REFERER'] ?? '', 'source' => $request->getParam('source') ?? '', 'tags' => $tags, 'default_private_links' => $this->container->conf->get('privacy.default_private_links', false), - ]; + 'async_metadata' => $this->container->conf->get('general.enable_async_metadata', true), + 'retrieve_description' => $this->container->conf->get('general.retrieve_description', false), + ]); - $data = $this->executeHooks('render_editlink', $data); + $this->executePageHooks('render_editlink', $data, TemplatePage::EDIT_LINK); foreach ($data as $key => $value) { $this->assignView($key, $value); @@ -368,19 +356,4 @@ class ManageShaareController extends ShaarliAdminController return $response->write($this->render(TemplatePage::EDIT_LINK)); } - - /** - * @param mixed[] $data Variables passed to the template engine - * - * @return mixed[] Template data after active plugins render_picwall hook execution. - */ - protected function executeHooks(string $hook, array $data): array - { - $this->container->pluginManager->executeHooks( - $hook, - $data - ); - - return $data; - } }