3 declare(strict_types
=1);
5 namespace Shaarli\Front\Controller\Admin
;
7 use Psr\Http\Message\UploadedFileInterface
;
8 use Shaarli\Render\TemplatePage
;
10 use Slim\Http\Response
;
13 * Class ImportController
15 * Slim controller used to display Shaarli data import page,
16 * and import bookmarks from Netscape Bookmarks file.
18 class ImportController
extends ShaarliAdminController
21 * GET /admin/import - Display import page
23 public function index(Request
$request, Response
$response): Response
28 ini_get('post_max_size'),
29 ini_get('upload_max_filesize'),
36 ini_get('post_max_size'),
37 ini_get('upload_max_filesize'),
41 $this->assignView('pagetitle', t('Import') . ' - ' . $this->container
->conf
->get('general.title', 'Shaarli'));
43 return $response->write($this->render(TemplatePage
::IMPORT
));
47 * POST /admin/import - Process import file provided and create bookmarks
49 public function import(Request
$request, Response
$response): Response
51 $this->checkToken($request);
53 $file = ($request->getUploadedFiles() ?? [])['filetoupload'] ?? null;
54 if (!$file instanceof UploadedFileInterface
) {
55 $this->saveErrorMessage(t('No import file provided.'));
57 return $this->redirect($response, '/admin/import');
61 // Import bookmarks from an uploaded file
62 if (0 === $file->getSize()) {
63 // The file is too big or some form field may be missing.
66 'The file you are trying to upload is probably bigger than what this webserver can accept'
67 . ' (%s). Please upload in smaller chunks.'
69 get_max_upload_size(ini_get('post_max_size'), ini_get('upload_max_filesize'))
71 $this->saveErrorMessage($msg);
73 return $this->redirect($response, '/admin/import');
76 $status = $this->container
->netscapeBookmarkUtils
->import($request->getParams(), $file);
78 $this->saveSuccessMessage($status);
80 return $this->redirect($response, '/admin/import');