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