]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Bookmark/importbookmarks.php
Merge branch '0.9.x' into socialbookmark
[quix0rs-gnu-social.git] / plugins / Bookmark / importbookmarks.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2010 StatusNet, Inc.
5  *
6  * Import a bookmarks file as notices
7  * 
8  * PHP version 5
9  *
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.
14  *
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.
19  *
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/>.
22  *
23  * @category  Bookmark
24  * @package   StatusNet
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/
29  */
30
31 define('INSTALLDIR', realpath(dirname(__FILE__) . '/../..'));
32
33 $shortoptions = 'i:n:f:';
34 $longoptions  = array('id=', 'nickname=', 'file=');
35
36 $helptext = <<<END_OF_IMPORTBOOKMARKS_HELP
37 importbookmarks.php [options]
38 Restore a backed-up Delicious.com bookmark file
39
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;
44
45 require_once INSTALLDIR.'/scripts/commandline.inc';
46
47 /**
48  * Get the bookmarks file as a string
49  * 
50  * Uses the -f or --file parameter to open and read a
51  * a bookmarks file
52  *
53  * @return string Contents of the file
54  */
55
56 function getBookmarksFile()
57 {
58     $filename = get_option_value('f', 'file');
59
60     if (empty($filename)) {
61         show_help();
62         exit(1);
63     }
64
65     if (!file_exists($filename)) {
66         throw new Exception("No such file '$filename'.");
67     }
68
69     if (!is_file($filename)) {
70         throw new Exception("Not a regular file: '$filename'.");
71     }
72
73     if (!is_readable($filename)) {
74         throw new Exception("File '$filename' not readable.");
75     }
76
77     // TRANS: %s is the filename that contains a backup for a user.
78     printfv(_("Getting backup from file '%s'.")."\n", $filename);
79
80     $html = file_get_contents($filename);
81
82     return $html;
83 }
84
85 try {
86     $user = getUser();
87     $html = getBookmarksFile();
88
89     $qm = QueueManager::get();
90     
91     $qm->enqueue(array($user, $html), 'dlcsback');
92
93 } catch (Exception $e) {
94     print $e->getMessage()."\n";
95     exit(1);
96 }