2009-09-17 13:52:03 +02:00
|
|
|
<?php
|
2007-12-12 17:29:16 +01:00
|
|
|
/***************************************************************************
|
2008-11-25 16:57:29 +01:00
|
|
|
Copyright (C) 2004 - 2006 Scuttle project
|
|
|
|
http://sourceforge.net/projects/scuttle/
|
|
|
|
http://scuttle.org/
|
2007-12-12 17:29:16 +01:00
|
|
|
|
2008-11-25 16:57:29 +01:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
2007-12-12 17:29:16 +01:00
|
|
|
|
2008-11-25 16:57:29 +01:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2007-12-12 17:29:16 +01:00
|
|
|
|
2008-11-25 16:57:29 +01:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
***************************************************************************/
|
2007-12-12 17:29:16 +01:00
|
|
|
|
2010-02-08 08:32:34 +01:00
|
|
|
require_once 'www-header.php';
|
2008-11-25 16:57:29 +01:00
|
|
|
|
|
|
|
/* Service creation: only useful services are created */
|
2008-12-05 08:25:04 +01:00
|
|
|
// No specific services
|
2008-11-25 16:57:29 +01:00
|
|
|
|
|
|
|
/* Managing all possible inputs */
|
|
|
|
// First input is $_FILES
|
|
|
|
// Other inputs
|
2012-01-20 21:27:04 +01:00
|
|
|
isset($_POST['status'])
|
|
|
|
? define('POST_STATUS', $_POST['status'])
|
|
|
|
: define('POST_STATUS', $GLOBALS['defaults']['privacy']);
|
2008-11-25 16:57:29 +01:00
|
|
|
|
|
|
|
|
2007-12-12 17:29:16 +01:00
|
|
|
if ($userservice->isLoggedOn() && sizeof($_FILES) > 0 && $_FILES['userfile']['size'] > 0) {
|
2008-11-25 16:57:29 +01:00
|
|
|
$userinfo = $userservice->getCurrentObjectUser();
|
|
|
|
|
|
|
|
if (is_numeric(POST_STATUS)) {
|
|
|
|
$status = intval(POST_STATUS);
|
|
|
|
} else {
|
2011-03-15 07:53:39 +01:00
|
|
|
$status = $GLOBALS['defaults']['privacy'];
|
2008-11-25 16:57:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$depth = array();
|
|
|
|
$xml_parser = xml_parser_create();
|
|
|
|
xml_set_element_handler($xml_parser, "startElement", "endElement");
|
|
|
|
|
|
|
|
if (!($fp = fopen($_FILES['userfile']['tmp_name'], "r")))
|
|
|
|
die(T_("Could not open XML input"));
|
|
|
|
|
|
|
|
while ($data = fread($fp, 4096)) {
|
|
|
|
if (!xml_parse($xml_parser, $data, feof($fp))) {
|
|
|
|
die(sprintf(T_("XML error: %s at line %d"),
|
|
|
|
xml_error_string(xml_get_error_code($xml_parser)),
|
|
|
|
xml_get_current_line_number($xml_parser)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xml_parser_free($xml_parser);
|
2012-01-20 21:27:04 +01:00
|
|
|
//FIXME: show errors and warnings
|
2008-11-25 16:57:29 +01:00
|
|
|
header('Location: '. createURL('bookmarks', $userinfo->getUsername()));
|
2007-12-12 17:29:16 +01:00
|
|
|
} else {
|
2008-11-25 16:57:29 +01:00
|
|
|
$templatename = 'importDelicious.tpl';
|
|
|
|
$tplVars['subtitle'] = T_('Import Bookmarks from del.icio.us');
|
|
|
|
$tplVars['formaction'] = createURL('import');
|
|
|
|
$templateservice->loadTemplate($templatename, $tplVars);
|
2007-12-12 17:29:16 +01:00
|
|
|
}
|
|
|
|
|
2008-11-25 16:57:29 +01:00
|
|
|
|
|
|
|
|
2007-12-12 17:29:16 +01:00
|
|
|
function startElement($parser, $name, $attrs) {
|
2008-11-25 16:57:29 +01:00
|
|
|
global $depth, $status, $tplVars, $userservice;
|
|
|
|
|
2009-10-23 19:13:16 +02:00
|
|
|
$bookmarkservice =SemanticScuttle_Service_Factory::get('Bookmark');
|
2008-11-25 16:57:29 +01:00
|
|
|
|
|
|
|
if ($name == 'POST') {
|
2012-01-20 21:27:04 +01:00
|
|
|
$newstatus = $status;
|
|
|
|
while (list($attrTitle, $attrVal) = each($attrs)) {
|
2008-11-25 16:57:29 +01:00
|
|
|
switch ($attrTitle) {
|
|
|
|
case 'HREF':
|
|
|
|
$bAddress = $attrVal;
|
|
|
|
break;
|
|
|
|
case 'DESCRIPTION':
|
|
|
|
$bTitle = $attrVal;
|
|
|
|
break;
|
|
|
|
case 'EXTENDED':
|
|
|
|
$bDescription = $attrVal;
|
|
|
|
break;
|
|
|
|
case 'TIME':
|
|
|
|
$bDatetime = $attrVal;
|
|
|
|
break;
|
|
|
|
case 'TAG':
|
|
|
|
$tags = strtolower($attrVal);
|
|
|
|
break;
|
2012-01-20 21:27:04 +01:00
|
|
|
case 'PRIVATE':
|
|
|
|
if ($attrVal == 'yes') {
|
|
|
|
$newstatus = 2;
|
|
|
|
}
|
|
|
|
break;
|
2008-11-25 16:57:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($bookmarkservice->bookmarkExists($bAddress, $userservice->getCurrentUserId())) {
|
|
|
|
$tplVars['error'] = T_('You have already submitted this bookmark.');
|
|
|
|
} else {
|
|
|
|
// Strangely, PHP can't work out full ISO 8601 dates, so we have to chop off the Z.
|
|
|
|
$bDatetime = substr($bDatetime, 0, -1);
|
|
|
|
|
|
|
|
// If bookmark claims to be from the future, set it to be now instead
|
|
|
|
if (strtotime($bDatetime) > time()) {
|
|
|
|
$bDatetime = gmdate('Y-m-d H:i:s');
|
|
|
|
}
|
|
|
|
|
2012-01-20 21:27:04 +01:00
|
|
|
$res = $bookmarkservice->addBookmark(
|
|
|
|
$bAddress, $bTitle, $bDescription, '', $newstatus, $tags,
|
|
|
|
null, $bDatetime, true, true
|
|
|
|
);
|
|
|
|
if ($res) {
|
|
|
|
$tplVars['msg'] = T_('Bookmark imported.');
|
|
|
|
} else {
|
|
|
|
$tplVars['error'] = T_('There was an error saving your bookmark. Please try again or contact the administrator.');
|
|
|
|
}
|
2008-11-25 16:57:29 +01:00
|
|
|
}
|
|
|
|
}
|
2012-01-20 21:27:04 +01:00
|
|
|
if (!isset($depth[$parser])) {
|
|
|
|
$depth[$parser] = 0;
|
|
|
|
}
|
2008-11-25 16:57:29 +01:00
|
|
|
$depth[$parser]++;
|
2007-12-12 17:29:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function endElement($parser, $name) {
|
2008-11-25 16:57:29 +01:00
|
|
|
global $depth;
|
|
|
|
$depth[$parser]--;
|
2007-12-12 17:29:16 +01:00
|
|
|
}
|
|
|
|
?>
|