X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=application%2FNetscapeBookmarkUtils.php;h=e0022fe1a391e333b0d58fcce8e4300fe66f2fa6;hb=f24896b237e40718fb6eaa2869592eb0855a47fd;hp=e7148d005776c7c41df62e72e5cba237a6a6f753;hpb=d592daea8343bb4dfecff5d97e93699581ccc58c;p=github%2Fshaarli%2FShaarli.git diff --git a/application/NetscapeBookmarkUtils.php b/application/NetscapeBookmarkUtils.php index e7148d00..e0022fe1 100644 --- a/application/NetscapeBookmarkUtils.php +++ b/application/NetscapeBookmarkUtils.php @@ -1,7 +1,15 @@ ') === false) { + if (preg_match('//i', $data) === 0) { return self::importStatus($filename, $filesize); } @@ -119,10 +133,20 @@ class NetscapeBookmarkUtils $defaultPrivacy = 0; $parser = new NetscapeBookmarkParser( - true, // nested tag support - $defaultTags, // additional user-specified tags - strval(1 - $defaultPrivacy) // defaultPub = 1 - defaultPrivacy + true, // nested tag support + $defaultTags, // additional user-specified tags + strval(1 - $defaultPrivacy), // defaultPub = 1 - defaultPrivacy + $conf->get('resource.data_dir') // log path, will be overridden ); + $logger = new Logger( + $conf->get('resource.data_dir'), + ! $conf->get('dev.debug') ? LogLevel::INFO : LogLevel::DEBUG, + [ + 'prefix' => 'import.', + 'extension' => 'log', + ] + ); + $parser->setLogger($logger); $bookmarks = $parser->parseString($data); $importCount = 0; @@ -134,13 +158,13 @@ class NetscapeBookmarkUtils if (empty($post['privacy']) || $post['privacy'] == 'default') { // use value from the imported file $private = $bkm['pub'] == '1' ? 0 : 1; - } else if ($post['privacy'] == 'private') { + } elseif ($post['privacy'] == 'private') { // all imported links are private $private = 1; - } else if ($post['privacy'] == 'public') { + } elseif ($post['privacy'] == 'public') { // all imported links are public $private = 0; - } + } $newLink = array( 'title' => $bkm['title'], @@ -163,6 +187,7 @@ class NetscapeBookmarkUtils $newLink['id'] = $existingLink['id']; $newLink['created'] = $existingLink['created']; $newLink['updated'] = new DateTime(); + $newLink['shorturl'] = $existingLink['shorturl']; $linkDb[$existingLink['id']] = $newLink; $importCount++; $overwriteCount++; @@ -179,13 +204,17 @@ class NetscapeBookmarkUtils $importCount++; } - $linkDb->save($pagecache); + $linkDb->save($conf->get('resource.page_cache')); + $history->importLinks(); + + $duration = time() - $start; return self::importStatus( $filename, $filesize, $importCount, $overwriteCount, - $skipCount + $skipCount, + $duration ); } }