3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2010 StatusNet, Inc.
6 * Import a bookmarks file as notices
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Affero General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Affero General Public License for more details.
20 * You should have received a copy of the GNU Affero General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 * @author Evan Prodromou <evan@status.net>
26 * @copyright 2010 StatusNet, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
28 * @link http://status.net/
31 define('INSTALLDIR', realpath(dirname(__FILE__) . '/../..'));
33 $shortoptions = 'i:n:f:';
34 $longoptions = array('id=', 'nickname=', 'file=');
36 $helptext = <<<END_OF_IMPORTBOOKMARKS_HELP
37 importbookmarks.php [options]
38 Restore a backed-up Delicious.com bookmark file
40 -i --id ID of user to import bookmarks for
41 -n --nickname nickname of the user to import for
42 -f --file file to read from (STDIN by default)
43 END_OF_IMPORTBOOKMARKS_HELP;
45 require_once INSTALLDIR.'/scripts/commandline.inc';
48 * Get the bookmarks file as a string
50 * Uses the -f or --file parameter to open and read a
53 * @return string Contents of the file
56 function getBookmarksFile()
58 $filename = get_option_value('f', 'file');
60 if (empty($filename)) {
65 if (!file_exists($filename)) {
66 throw new Exception("No such file '$filename'.");
69 if (!is_file($filename)) {
70 throw new Exception("Not a regular file: '$filename'.");
73 if (!is_readable($filename)) {
74 throw new Exception("File '$filename' not readable.");
77 // TRANS: %s is the filename that contains a backup for a user.
78 printfv(_("Getting backup from file '%s'.")."\n", $filename);
80 $html = file_get_contents($filename);
87 $html = getBookmarksFile();
89 $qm = QueueManager::get();
91 $qm->enqueue(array($user, $html), 'dlcsback');
93 } catch (Exception $e) {
94 print $e->getMessage()."\n";