aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/netscape
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-06-17 19:08:02 +0200
committerArthurHoaro <arthur@hoa.ro>2020-07-23 21:19:21 +0200
commit78657347c5b463d7c22bfc8c87b7db39fe058833 (patch)
treea61c513ce05a597119cb5e9e65a33a94e01663d9 /application/netscape
parentc70ff64a61d62cc8d35a62f30596ecc2a3c578a3 (diff)
downloadShaarli-78657347c5b463d7c22bfc8c87b7db39fe058833.tar.gz
Shaarli-78657347c5b463d7c22bfc8c87b7db39fe058833.tar.zst
Shaarli-78657347c5b463d7c22bfc8c87b7db39fe058833.zip
Process bookmarks import through Slim controller
Diffstat (limited to 'application/netscape')
-rw-r--r--application/netscape/NetscapeBookmarkUtils.php15
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;
6use DateTimeZone; 6use DateTimeZone;
7use Exception; 7use Exception;
8use Katzgrau\KLogger\Logger; 8use Katzgrau\KLogger\Logger;
9use Psr\Http\Message\UploadedFileInterface;
9use Psr\Log\LogLevel; 10use Psr\Log\LogLevel;
10use Shaarli\Bookmark\Bookmark; 11use Shaarli\Bookmark\Bookmark;
11use Shaarli\Bookmark\BookmarkServiceInterface; 12use 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?