X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FBookmark%2Fdeliciousbackupimporter.php;h=0ceba61d89a1619b009cf771bf4e20b82b335a1a;hb=59043dca7fb6f974b11797c4d0f20e5b78b0611d;hp=a8d2819fe7c0f04bff88c0b93d242f7cf93b6ee0;hpb=14456cbbb2b8f9266eb5ca13acff77e6b6699ac2;p=quix0rs-gnu-social.git diff --git a/plugins/Bookmark/deliciousbackupimporter.php b/plugins/Bookmark/deliciousbackupimporter.php index a8d2819fe7..0ceba61d89 100644 --- a/plugins/Bookmark/deliciousbackupimporter.php +++ b/plugins/Bookmark/deliciousbackupimporter.php @@ -4,7 +4,7 @@ * Copyright (C) 2010, StatusNet, Inc. * * Importer class for Delicious.com backups - * + * * PHP version 5 * * This program is free software: you can redistribute it and/or modify @@ -44,7 +44,6 @@ if (!defined('STATUSNET')) { * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 * @link http://status.net/ */ - class DeliciousBackupImporter extends QueueHandler { /** @@ -52,7 +51,6 @@ class DeliciousBackupImporter extends QueueHandler * * @return string transport string */ - function transport() { return 'dlcsback'; @@ -72,17 +70,30 @@ class DeliciousBackupImporter extends QueueHandler * * @return boolean success value */ - function handle($data) { list($user, $body) = $data; - $doc = $this->importHTML($body); + try { + $doc = $this->importHTML($body); + } catch (ClientException $cex) { + // XXX: message to the user + common_log(LOG_WARNING, $cex->getMessage()); + return true; + } + + // If we can't parse it, it's no good + + if (empty($doc)) { + return true; + } $dls = $doc->getElementsByTagName('dl'); if ($dls->length != 1) { - throw new ClientException(_m("Bad import file.")); + // XXX: message to the user + common_log(LOG_WARNING, 'Bad input file'); + return true; } $dl = $dls->item(0); @@ -112,9 +123,11 @@ class DeliciousBackupImporter extends QueueHandler case 'dd': $dd = $child; - // This
contains a description for the bookmark in - // the preceding
node. - $saved = $this->importBookmark($user, $dt, $dd); + if (!empty($dt)) { + // This
contains a description for the bookmark in + // the preceding
node. + $saved = $this->importBookmark($user, $dt, $dd); + } $dt = null; $dd = null; @@ -123,7 +136,7 @@ class DeliciousBackupImporter extends QueueHandler common_log(LOG_INFO, 'Skipping the

in the

.'); break; default: - common_log(LOG_WARNING, + common_log(LOG_WARNING, "Unexpected element $child->tagName ". " found in import."); } @@ -146,12 +159,12 @@ class DeliciousBackupImporter extends QueueHandler /** * Import a single bookmark - * + * * Takes a
/
pair. The
has a single * in it with some non-standard attributes. - * + * * A
sequence will appear as a
with - * anothe
as a child. We handle this case recursively. + * anothe
as a child. We handle this case recursively. * * @param User $user User to import data as * @param DOMElement $dt
element @@ -159,12 +172,12 @@ class DeliciousBackupImporter extends QueueHandler * * @return Notice imported notice */ - function importBookmark($user, $dt, $dd = null) { $as = $dt->getElementsByTagName('a'); if ($as->length == 0) { + // TRANS: Client exception thrown when a bookmark in an import file is incorrectly formatted. throw new ClientException(_m("No tag in a
.")); } @@ -173,6 +186,7 @@ class DeliciousBackupImporter extends QueueHandler $private = $a->getAttribute('private'); if ($private != 0) { + // TRANS: Client exception thrown when a bookmark in an import file is private. throw new ClientException(_m('Skipping private bookmark.')); } @@ -306,5 +320,4 @@ class DeliciousBackupImporter extends QueueHandler $this->fixListItem($node); } } - }