use DateTimeZone;
use Exception;
use Katzgrau\KLogger\Logger;
+use Psr\Http\Message\UploadedFileInterface;
use Psr\Log\LogLevel;
use Shaarli\Bookmark\Bookmark;
use Shaarli\Bookmark\BookmarkServiceInterface;
$indexUrl
) {
// see tpl/export.html for possible values
- if (!in_array($selection, array('all', 'public', 'private'))) {
+ if (!in_array($selection, ['all', 'public', 'private'])) {
throw new Exception(t('Invalid export selection:') . ' "' . $selection . '"');
}
- $bookmarkLinks = array();
- foreach ($this->bookmarkService->search([], $selection) as $bookmark) {
+ $bookmarkLinks = [];
+ foreach ($this->bookmarkService->search([], $selection)->getBookmarks() as $bookmark) {
$link = $formatter->format($bookmark);
$link['taglist'] = implode(',', $bookmark->getTags());
if ($bookmark->isNote() && $prependNoteUrl) {
- $link['url'] = $indexUrl . $link['url'];
+ $link['url'] = rtrim($indexUrl, '/') . '/' . ltrim($link['url'], '/');
}
$bookmarkLinks[] = $link;
/**
* Imports Web bookmarks from an uploaded Netscape bookmark dump
*
- * @param array $post Server $_POST parameters
- * @param array $files Server $_FILES parameters
+ * @param array $post Server $_POST parameters
+ * @param UploadedFileInterface $file File in PSR-7 object format
*
* @return string Summary of the bookmark import status
*/
- public function import($post, $files)
+ public function import($post, UploadedFileInterface $file)
{
$start = time();
- $filename = $files['filetoupload']['name'];
- $filesize = $files['filetoupload']['size'];
- $data = file_get_contents($files['filetoupload']['tmp_name']);
+ $filename = $file->getClientFilename();
+ $filesize = $file->getSize();
+ $data = (string) $file->getStream();
if (preg_match('/<!DOCTYPE NETSCAPE-Bookmark-file-1>/i', $data) === 0) {
- return self::importStatus($filename, $filesize);
+ return $this->importStatus($filename, $filesize);
}
// Overwrite existing bookmarks?
// Add tags to all imported bookmarks?
if (empty($post['default_tags'])) {
- $defaultTags = array();
+ $defaultTags = [];
} else {
- $defaultTags = preg_split(
- '/[\s,]+/',
- escape($post['default_tags'])
+ $defaultTags = tags_str2array(
+ escape($post['default_tags']),
+ $this->conf->get('general.tags_separator', ' ')
);
}
$link->setUrl($bkm['uri'], $this->conf->get('security.allowed_protocols'));
$link->setDescription($bkm['note']);
$link->setPrivate($private);
- $link->setTagsString($bkm['tags']);
+ $link->setTags($bkm['tags']);
$this->bookmarkService->addOrSet($link, false);
$importCount++;