2 /***************************************************************************
3 Copyright (C) 2004 - 2006 Scuttle project
4 http://sourceforge.net/projects/scuttle/
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 ***************************************************************************/
22 require_once('header.inc.php');
23 $userservice =& ServiceFactory::getServiceInstance('UserService');
24 $templateservice =& ServiceFactory::getServiceInstance('TemplateService');
27 if ($userservice->isLoggedOn() && sizeof($_FILES) > 0 && $_FILES['userfile']['size'] > 0) {
28 $userinfo = $userservice->getCurrentUser();
30 if (isset($_POST['status']) && is_numeric($_POST['status'])) {
31 $status = intval($_POST['status']);
37 $xml_parser = xml_parser_create();
38 xml_set_element_handler($xml_parser, "startElement", "endElement");
40 if (!($fp = fopen($_FILES['userfile']['tmp_name'], "r")))
41 die(T_("Could not open XML input"));
43 while ($data = fread($fp, 4096)) {
44 if (!xml_parse($xml_parser, $data, feof($fp))) {
45 die(sprintf(T_("XML error: %s at line %d"),
46 xml_error_string(xml_get_error_code($xml_parser)),
47 xml_get_current_line_number($xml_parser)));
50 xml_parser_free($xml_parser);
51 header('Location: '. createURL('bookmarks', $userinfo[$userservice->getFieldName('username')]));
53 $templatename = 'importDelicious.tpl';
54 $tplVars['subtitle'] = T_('Import Bookmarks from del.icio.us');
55 $tplVars['formaction'] = createURL('import');
56 $templateservice->loadTemplate($templatename, $tplVars);
59 function startElement($parser, $name, $attrs) {
60 global $depth, $status, $tplVars, $userservice;
62 $bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
63 $userservice =& ServiceFactory::getServiceInstance('UserService');
65 if ($name == 'POST') {
66 while(list($attrTitle, $attrVal) = each($attrs)) {
75 $bDescription = $attrVal;
78 $bDatetime = $attrVal;
81 $tags = strtolower($attrVal);
85 if ($bookmarkservice->bookmarkExists($bAddress, $userservice->getCurrentUserId())) {
86 $tplVars['error'] = T_('You have already submitted this bookmark.');
88 // Strangely, PHP can't work out full ISO 8601 dates, so we have to chop off the Z.
89 $bDatetime = substr($bDatetime, 0, -1);
91 // If bookmark claims to be from the future, set it to be now instead
92 if (strtotime($bDatetime) > time()) {
93 $bDatetime = gmdate('Y-m-d H:i:s');
96 if ($bookmarkservice->addBookmark($bAddress, $bTitle, $bDescription, $status, $tags, $bDatetime, true, true))
97 $tplVars['msg'] = T_('Bookmark imported.');
99 $tplVars['error'] = T_('There was an error saving your bookmark. Please try again or contact the administrator.');
105 function endElement($parser, $name) {