aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/front/controller/admin/MetadataController.php
blob: ff845944986633108913f4a5d77c2132ff5dbd42 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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([]);
    }
}