diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-06-17 19:08:02 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2020-07-23 21:19:21 +0200 |
commit | 78657347c5b463d7c22bfc8c87b7db39fe058833 (patch) | |
tree | a61c513ce05a597119cb5e9e65a33a94e01663d9 /application/netscape/NetscapeBookmarkUtils.php | |
parent | c70ff64a61d62cc8d35a62f30596ecc2a3c578a3 (diff) | |
download | Shaarli-78657347c5b463d7c22bfc8c87b7db39fe058833.tar.gz Shaarli-78657347c5b463d7c22bfc8c87b7db39fe058833.tar.zst Shaarli-78657347c5b463d7c22bfc8c87b7db39fe058833.zip |
Process bookmarks import through Slim controller
Diffstat (limited to 'application/netscape/NetscapeBookmarkUtils.php')
-rw-r--r-- | application/netscape/NetscapeBookmarkUtils.php | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/application/netscape/NetscapeBookmarkUtils.php b/application/netscape/NetscapeBookmarkUtils.php index 8557cca2..b150f649 100644 --- a/application/netscape/NetscapeBookmarkUtils.php +++ b/application/netscape/NetscapeBookmarkUtils.php | |||
@@ -6,6 +6,7 @@ use DateTime; | |||
6 | use DateTimeZone; | 6 | use DateTimeZone; |
7 | use Exception; | 7 | use Exception; |
8 | use Katzgrau\KLogger\Logger; | 8 | use Katzgrau\KLogger\Logger; |
9 | use Psr\Http\Message\UploadedFileInterface; | ||
9 | use Psr\Log\LogLevel; | 10 | use Psr\Log\LogLevel; |
10 | use Shaarli\Bookmark\Bookmark; | 11 | use Shaarli\Bookmark\Bookmark; |
11 | use Shaarli\Bookmark\BookmarkServiceInterface; | 12 | use Shaarli\Bookmark\BookmarkServiceInterface; |
@@ -79,20 +80,20 @@ class NetscapeBookmarkUtils | |||
79 | /** | 80 | /** |
80 | * Imports Web bookmarks from an uploaded Netscape bookmark dump | 81 | * Imports Web bookmarks from an uploaded Netscape bookmark dump |
81 | * | 82 | * |
82 | * @param array $post Server $_POST parameters | 83 | * @param array $post Server $_POST parameters |
83 | * @param array $files Server $_FILES parameters | 84 | * @param UploadedFileInterface $file File in PSR-7 object format |
84 | * | 85 | * |
85 | * @return string Summary of the bookmark import status | 86 | * @return string Summary of the bookmark import status |
86 | */ | 87 | */ |
87 | public function import($post, $files) | 88 | public function import($post, UploadedFileInterface $file) |
88 | { | 89 | { |
89 | $start = time(); | 90 | $start = time(); |
90 | $filename = $files['filetoupload']['name']; | 91 | $filename = $file->getClientFilename(); |
91 | $filesize = $files['filetoupload']['size']; | 92 | $filesize = $file->getSize(); |
92 | $data = file_get_contents($files['filetoupload']['tmp_name']); | 93 | $data = (string) $file->getStream(); |
93 | 94 | ||
94 | if (preg_match('/<!DOCTYPE NETSCAPE-Bookmark-file-1>/i', $data) === 0) { | 95 | if (preg_match('/<!DOCTYPE NETSCAPE-Bookmark-file-1>/i', $data) === 0) { |
95 | return self::importStatus($filename, $filesize); | 96 | return $this->importStatus($filename, $filesize); |
96 | } | 97 | } |
97 | 98 | ||
98 | // Overwrite existing bookmarks? | 99 | // Overwrite existing bookmarks? |