3 declare(strict_types
=1);
5 namespace Shaarli\Front\Controller\Admin
;
7 use Psr\Http\Message\UploadedFileInterface
;
9 use Slim\Http\Response
;
12 * Class ImportController
14 * Slim controller used to display Shaarli data import page,
15 * and import bookmarks from Netscape Bookmarks file.
17 class ImportController
extends ShaarliAdminController
20 * GET /admin/import - Display import page
22 public function index(Request
$request, Response
$response): Response
27 ini_get('post_max_size'),
28 ini_get('upload_max_filesize'),
35 ini_get('post_max_size'),
36 ini_get('upload_max_filesize'),
40 $this->assignView('pagetitle', t('Import') .' - '. $this->container
->conf
->get('general.title', 'Shaarli'));
42 return $response->write($this->render('import'));
46 * POST /admin/import - Process import file provided and create bookmarks
48 public function import(Request
$request, Response
$response): Response
50 $this->checkToken($request);
52 $file = ($request->getUploadedFiles() ?? [])['filetoupload'] ?? null;
53 if (!$file instanceof UploadedFileInterface
) {
54 $this->saveErrorMessage(t('No import file provided.'));
56 return $this->redirect($response, '/admin/import');
60 // Import bookmarks from an uploaded file
61 if (0 === $file->getSize()) {
62 // The file is too big or some form field may be missing.
65 'The file you are trying to upload is probably bigger than what this webserver can accept'
66 .' (%s). Please upload in smaller chunks.'
68 get_max_upload_size(ini_get('post_max_size'), ini_get('upload_max_filesize'))
70 $this->saveErrorMessage($msg);
72 return $this->redirect($response, '/admin/import');
75 $status = $this->container
->netscapeBookmarkUtils
->import($request->getParams(), $file);
77 $this->saveSuccessMessage($status);
79 return $this->redirect($response, '/admin/import');