X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=application%2FNetscapeBookmarkUtils.php;h=84dd2b2083e36f8d20755fbdb2d97502c83b15cd;hb=9d9f6d75b94aab51067bdfbe50b58b66d1194f6d;hp=8a939adbff68ec995870140ca2ccfd66030a0cd8;hpb=01878a75b93b9966f7366ea2937c118bbc3e459e;p=github%2Fshaarli%2FShaarli.git diff --git a/application/NetscapeBookmarkUtils.php b/application/NetscapeBookmarkUtils.php index 8a939adb..84dd2b20 100644 --- a/application/NetscapeBookmarkUtils.php +++ b/application/NetscapeBookmarkUtils.php @@ -1,7 +1,13 @@ ') === false) { + if (preg_match('//i', $data) === 0) { return self::importStatus($filename, $filesize); } @@ -119,10 +131,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 +156,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 +185,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++; @@ -174,17 +197,22 @@ class NetscapeBookmarkUtils $newLinkDate->setTimezone(new DateTimeZone(date_default_timezone_get())); $newLink['created'] = $newLinkDate; $newLink['id'] = $linkDb->getNextId(); + $newLink['shorturl'] = link_small_hash($newLink['created'], $newLink['id']); $linkDb[$newLink['id']] = $newLink; $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 ); } }