Netscape bookmark parser: bump to new major version
Apply breaking changes of the new version: - parsed bookmarks have different field names - default values (private and tags) are no longer handled by the library - constructor signature has been updated
This commit is contained in:
parent
130008da03
commit
bde1fdcb48
3 changed files with 42 additions and 36 deletions
|
@ -109,15 +109,9 @@ public function import($post, UploadedFileInterface $file)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// bookmarks are imported as public by default
|
// Optionally Force all imported link to be either public or private.
|
||||||
$defaultPrivacy = 0;
|
$forcedPrivateStatus = !empty($post['privacy']) ? (string) $post['privacy'] : null;
|
||||||
|
|
||||||
$parser = new NetscapeBookmarkParser(
|
|
||||||
true, // nested tag support
|
|
||||||
$defaultTags, // additional user-specified tags
|
|
||||||
strval(1 - $defaultPrivacy), // defaultPub = 1 - defaultPrivacy
|
|
||||||
$this->conf->get('resource.data_dir') // log path, will be overridden
|
|
||||||
);
|
|
||||||
$logger = new Logger(
|
$logger = new Logger(
|
||||||
$this->conf->get('resource.data_dir'),
|
$this->conf->get('resource.data_dir'),
|
||||||
!$this->conf->get('dev.debug') ? LogLevel::INFO : LogLevel::DEBUG,
|
!$this->conf->get('dev.debug') ? LogLevel::INFO : LogLevel::DEBUG,
|
||||||
|
@ -126,7 +120,8 @@ public function import($post, UploadedFileInterface $file)
|
||||||
'extension' => 'log',
|
'extension' => 'log',
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
$parser->setLogger($logger);
|
$parser = new NetscapeBookmarkParser([], $logger);
|
||||||
|
|
||||||
$bookmarks = $parser->parseString($data);
|
$bookmarks = $parser->parseString($data);
|
||||||
|
|
||||||
$importCount = 0;
|
$importCount = 0;
|
||||||
|
@ -134,19 +129,18 @@ public function import($post, UploadedFileInterface $file)
|
||||||
$skipCount = 0;
|
$skipCount = 0;
|
||||||
|
|
||||||
foreach ($bookmarks as $bkm) {
|
foreach ($bookmarks as $bkm) {
|
||||||
$private = $defaultPrivacy;
|
if ($forcedPrivateStatus == 'private') {
|
||||||
if (empty($post['privacy']) || $post['privacy'] == 'default') {
|
|
||||||
// use value from the imported file
|
|
||||||
$private = $bkm['pub'] == '1' ? 0 : 1;
|
|
||||||
} elseif ($post['privacy'] == 'private') {
|
|
||||||
// all imported bookmarks are private
|
// all imported bookmarks are private
|
||||||
$private = 1;
|
$isPrivate = true;
|
||||||
} elseif ($post['privacy'] == 'public') {
|
} elseif ($forcedPrivateStatus == 'public') {
|
||||||
// all imported bookmarks are public
|
// all imported bookmarks are public
|
||||||
$private = 0;
|
$isPrivate = false;
|
||||||
|
} else {
|
||||||
|
// Use private value from imported file or default to public
|
||||||
|
$isPrivate = isset($bkm['public']) && !$bkm['public'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$link = $this->bookmarkService->findByUrl($bkm['uri']);
|
$link = $this->bookmarkService->findByUrl($bkm['url']);
|
||||||
$existingLink = $link !== null;
|
$existingLink = $link !== null;
|
||||||
if (! $existingLink) {
|
if (! $existingLink) {
|
||||||
$link = new Bookmark();
|
$link = new Bookmark();
|
||||||
|
@ -162,15 +156,19 @@ public function import($post, UploadedFileInterface $file)
|
||||||
$link->setUpdated(new DateTime());
|
$link->setUpdated(new DateTime());
|
||||||
$overwriteCount++;
|
$overwriteCount++;
|
||||||
} else {
|
} else {
|
||||||
$newLinkDate = new DateTime('@' . strval($bkm['time']));
|
$newLinkDate = new DateTime('@' . $bkm['dateCreated']);
|
||||||
$newLinkDate->setTimezone(new DateTimeZone(date_default_timezone_get()));
|
$newLinkDate->setTimezone(new DateTimeZone(date_default_timezone_get()));
|
||||||
$link->setCreated($newLinkDate);
|
$link->setCreated($newLinkDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
$link->setTitle($bkm['title']);
|
if (!empty($defaultTags)) {
|
||||||
$link->setUrl($bkm['uri'], $this->conf->get('security.allowed_protocols'));
|
$bkm['tags'] = array_merge($defaultTags, $bkm['tags']);
|
||||||
$link->setDescription($bkm['note']);
|
}
|
||||||
$link->setPrivate($private);
|
|
||||||
|
$link->setTitle($bkm['name']);
|
||||||
|
$link->setUrl($bkm['url'], $this->conf->get('security.allowed_protocols'));
|
||||||
|
$link->setDescription($bkm['description']);
|
||||||
|
$link->setPrivate($isPrivate);
|
||||||
$link->setTags($bkm['tags']);
|
$link->setTags($bkm['tags']);
|
||||||
|
|
||||||
$this->bookmarkService->addOrSet($link, false);
|
$this->bookmarkService->addOrSet($link, false);
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
"katzgrau/klogger": "^1.2",
|
"katzgrau/klogger": "^1.2",
|
||||||
"malkusch/lock": "^2.1",
|
"malkusch/lock": "^2.1",
|
||||||
"pubsubhubbub/publisher": "dev-master",
|
"pubsubhubbub/publisher": "dev-master",
|
||||||
"shaarli/netscape-bookmark-parser": "^3.0",
|
"shaarli/netscape-bookmark-parser": "^4.0",
|
||||||
"slim/slim": "^3.0"
|
"slim/slim": "^3.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
|
|
32
composer.lock
generated
32
composer.lock
generated
|
@ -4,7 +4,7 @@
|
||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "83852dec81e299a117a81206a5091472",
|
"content-hash": "326e743376bd043cd7de28c02b5ac1d5",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "arthurhoaro/web-thumbnailer",
|
"name": "arthurhoaro/web-thumbnailer",
|
||||||
|
@ -806,21 +806,21 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "shaarli/netscape-bookmark-parser",
|
"name": "shaarli/netscape-bookmark-parser",
|
||||||
"version": "v3.2.0",
|
"version": "v4.0.0",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/shaarli/netscape-bookmark-parser.git",
|
"url": "https://github.com/shaarli/netscape-bookmark-parser.git",
|
||||||
"reference": "5b2eb8d478f5e6938359e116880763e6b1892e62"
|
"reference": "aa024e5731959966660d98fcefe27deada40d88e"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/shaarli/netscape-bookmark-parser/zipball/5b2eb8d478f5e6938359e116880763e6b1892e62",
|
"url": "https://api.github.com/repos/shaarli/netscape-bookmark-parser/zipball/aa024e5731959966660d98fcefe27deada40d88e",
|
||||||
"reference": "5b2eb8d478f5e6938359e116880763e6b1892e62",
|
"reference": "aa024e5731959966660d98fcefe27deada40d88e",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"katzgrau/klogger": "~1.0",
|
"php": ">=7.1",
|
||||||
"php": ">=7.1"
|
"psr/log": "^1.1"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "^7.0 || ^8.0 || ^9.0",
|
"phpunit/phpunit": "^7.0 || ^8.0 || ^9.0",
|
||||||
|
@ -828,9 +828,9 @@
|
||||||
},
|
},
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"files": [
|
"psr-4": {
|
||||||
"NetscapeBookmarkParser.php"
|
"Shaarli\\NetscapeBookmarkParser\\": "src/"
|
||||||
]
|
}
|
||||||
},
|
},
|
||||||
"notification-url": "https://packagist.org/downloads/",
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
"license": [
|
"license": [
|
||||||
|
@ -848,21 +848,29 @@
|
||||||
"email": "virtualtam@flibidi.net",
|
"email": "virtualtam@flibidi.net",
|
||||||
"homepage": "https://github.com/virtualtam",
|
"homepage": "https://github.com/virtualtam",
|
||||||
"role": "Developer"
|
"role": "Developer"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Matthias Morin",
|
||||||
|
"email": "mat@tangoman.io",
|
||||||
|
"homepage": "https://github.com/TangoMan75",
|
||||||
|
"role": "Developer"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Generic Netscape bookmark parser",
|
"description": "Generic Netscape bookmark parser",
|
||||||
"homepage": "https://github.com/shaarli/netscape-bookmark-parser",
|
"homepage": "https://github.com/shaarli/netscape-bookmark-parser",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"bookmark",
|
"bookmark",
|
||||||
|
"decoder",
|
||||||
|
"encoder",
|
||||||
"link",
|
"link",
|
||||||
"netscape",
|
"netscape",
|
||||||
"parse"
|
"parse"
|
||||||
],
|
],
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/shaarli/netscape-bookmark-parser/issues",
|
"issues": "https://github.com/shaarli/netscape-bookmark-parser/issues",
|
||||||
"source": "https://github.com/shaarli/netscape-bookmark-parser/tree/v3.2.0"
|
"source": "https://github.com/shaarli/netscape-bookmark-parser/tree/v4.0.0"
|
||||||
},
|
},
|
||||||
"time": "2021-01-31T09:39:07+00:00"
|
"time": "2022-08-13T09:57:26+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "slim/slim",
|
"name": "slim/slim",
|
||||||
|
|
Loading…
Reference in a new issue