diff options
Diffstat (limited to 'application/NetscapeBookmarkUtils.php')
-rw-r--r-- | application/NetscapeBookmarkUtils.php | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/application/NetscapeBookmarkUtils.php b/application/NetscapeBookmarkUtils.php index e7148d00..f467a074 100644 --- a/application/NetscapeBookmarkUtils.php +++ b/application/NetscapeBookmarkUtils.php | |||
@@ -1,7 +1,12 @@ | |||
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | use Psr\Log\LogLevel; | ||
4 | use Shaarli\NetscapeBookmarkParser\NetscapeBookmarkParser; | ||
5 | use Katzgrau\KLogger\Logger; | ||
6 | |||
3 | /** | 7 | /** |
4 | * Utilities to import and export bookmarks using the Netscape format | 8 | * Utilities to import and export bookmarks using the Netscape format |
9 | * TODO: Not static, use a container. | ||
5 | */ | 10 | */ |
6 | class NetscapeBookmarkUtils | 11 | class NetscapeBookmarkUtils |
7 | { | 12 | { |
@@ -85,14 +90,14 @@ class NetscapeBookmarkUtils | |||
85 | /** | 90 | /** |
86 | * Imports Web bookmarks from an uploaded Netscape bookmark dump | 91 | * Imports Web bookmarks from an uploaded Netscape bookmark dump |
87 | * | 92 | * |
88 | * @param array $post Server $_POST parameters | 93 | * @param array $post Server $_POST parameters |
89 | * @param array $files Server $_FILES parameters | 94 | * @param array $files Server $_FILES parameters |
90 | * @param LinkDB $linkDb Loaded LinkDB instance | 95 | * @param LinkDB $linkDb Loaded LinkDB instance |
91 | * @param string $pagecache Page cache | 96 | * @param ConfigManager $conf instance |
92 | * | 97 | * |
93 | * @return string Summary of the bookmark import status | 98 | * @return string Summary of the bookmark import status |
94 | */ | 99 | */ |
95 | public static function import($post, $files, $linkDb, $pagecache) | 100 | public static function import($post, $files, $linkDb, $conf) |
96 | { | 101 | { |
97 | $filename = $files['filetoupload']['name']; | 102 | $filename = $files['filetoupload']['name']; |
98 | $filesize = $files['filetoupload']['size']; | 103 | $filesize = $files['filetoupload']['size']; |
@@ -119,10 +124,20 @@ class NetscapeBookmarkUtils | |||
119 | $defaultPrivacy = 0; | 124 | $defaultPrivacy = 0; |
120 | 125 | ||
121 | $parser = new NetscapeBookmarkParser( | 126 | $parser = new NetscapeBookmarkParser( |
122 | true, // nested tag support | 127 | true, // nested tag support |
123 | $defaultTags, // additional user-specified tags | 128 | $defaultTags, // additional user-specified tags |
124 | strval(1 - $defaultPrivacy) // defaultPub = 1 - defaultPrivacy | 129 | strval(1 - $defaultPrivacy), // defaultPub = 1 - defaultPrivacy |
130 | $conf->get('resource.data_dir') // log path, will be overridden | ||
131 | ); | ||
132 | $logger = new Logger( | ||
133 | $conf->get('resource.data_dir'), | ||
134 | ! $conf->get('dev.debug') ? LogLevel::INFO : LogLevel::DEBUG, | ||
135 | [ | ||
136 | 'prefix' => 'import.', | ||
137 | 'extension' => 'log', | ||
138 | ] | ||
125 | ); | 139 | ); |
140 | $parser->setLogger($logger); | ||
126 | $bookmarks = $parser->parseString($data); | 141 | $bookmarks = $parser->parseString($data); |
127 | 142 | ||
128 | $importCount = 0; | 143 | $importCount = 0; |
@@ -179,7 +194,7 @@ class NetscapeBookmarkUtils | |||
179 | $importCount++; | 194 | $importCount++; |
180 | } | 195 | } |
181 | 196 | ||
182 | $linkDb->save($pagecache); | 197 | $linkDb->save($conf->get('resource.page_cache')); |
183 | return self::importStatus( | 198 | return self::importStatus( |
184 | $filename, | 199 | $filename, |
185 | $filesize, | 200 | $filesize, |