Add a setting to retrieve bookmark metadata asynchrounously
- There is a new standalone script (metadata.js) which requests a new controller to get bookmark metadata and fill the form async - This feature is enabled with the new setting: general.enable_async_metadata (enabled by default) - general.retrieve_description is now enabled by default - A small rotating loader animation has a been added to bookmark inputs when metadata is being retrieved (default template) - Custom JS htmlentities has been removed and mathiasbynens/he library is used instead Fixes #1563
This commit is contained in:
parent
f34554c6c2
commit
4cf3564d28
19 changed files with 447 additions and 75 deletions
application/front/controller/admin
|
@ -53,36 +53,22 @@ 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' && mb_check_encoding($charset)) {
|
||||
$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 = [
|
||||
'title' => $title,
|
||||
'title' => $title ?? $metadata['title'] ?? '',
|
||||
'url' => $url ?? '',
|
||||
'description' => $description ?? '',
|
||||
'tags' => $tags ?? '',
|
||||
'description' => $description ?? $metadata['description'] ?? '',
|
||||
'tags' => $tags ?? $metadata['tags'] ?? '',
|
||||
'private' => $private,
|
||||
];
|
||||
} else {
|
||||
|
@ -352,6 +338,8 @@ class ManageShaareController extends ShaarliAdminController
|
|||
'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),
|
||||
]);
|
||||
|
||||
$this->executePageHooks('render_editlink', $data, TemplatePage::EDIT_LINK);
|
||||
|
|
29
application/front/controller/admin/MetadataController.php
Normal file
29
application/front/controller/admin/MetadataController.php
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Shaarli\Front\Controller\Admin;
|
||||
|
||||
use Slim\Http\Request;
|
||||
use Slim\Http\Response;
|
||||
|
||||
/**
|
||||
* Controller used to retrieve/update bookmark's metadata.
|
||||
*/
|
||||
class MetadataController extends ShaarliAdminController
|
||||
{
|
||||
/**
|
||||
* GET /admin/metadata/{url} - Attempt to retrieve the bookmark title from provided URL.
|
||||
*/
|
||||
public function ajaxRetrieveTitle(Request $request, Response $response): Response
|
||||
{
|
||||
$url = $request->getParam('url');
|
||||
|
||||
// Only try to extract metadata from URL with HTTP(s) scheme
|
||||
if (!empty($url) && strpos(get_url_scheme($url) ?: '', 'http') !== false) {
|
||||
return $response->withJson($this->container->metadataRetriever->retrieve($url));
|
||||
}
|
||||
|
||||
return $response->withJson([]);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue