From 15b91c7e661d928d8b125ec9cfbda1702319c8b4 Mon Sep 17 00:00:00 2001 From: mensonge Date: Tue, 25 Nov 2008 15:57:29 +0000 Subject: Major refactoring: transform user into object, define parameters used into each file, ... git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@173 b3834d28-1941-0410-a4f8-b48e95affb8f --- import.php | 188 ++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 100 insertions(+), 88 deletions(-) (limited to 'import.php') diff --git a/import.php b/import.php index f25b439..8d051c8 100644 --- a/import.php +++ b/import.php @@ -1,109 +1,121 @@ isLoggedOn() && sizeof($_FILES) > 0 && $_FILES['userfile']['size'] > 0) { - $userinfo = $userservice->getCurrentUser(); - - if (isset($_POST['status']) && is_numeric($_POST['status'])) { - $status = intval($_POST['status']); - } else { - $status = 2; - } - - $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); - header('Location: '. createURL('bookmarks', $userinfo[$userservice->getFieldName('username')])); + $userinfo = $userservice->getCurrentObjectUser(); + + if (is_numeric(POST_STATUS)) { + $status = intval(POST_STATUS); + } else { + $status = 2; + } + + $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); + header('Location: '. createURL('bookmarks', $userinfo->getUsername())); } else { - $templatename = 'importDelicious.tpl'; - $tplVars['subtitle'] = T_('Import Bookmarks from del.icio.us'); - $tplVars['formaction'] = createURL('import'); - $templateservice->loadTemplate($templatename, $tplVars); + $templatename = 'importDelicious.tpl'; + $tplVars['subtitle'] = T_('Import Bookmarks from del.icio.us'); + $tplVars['formaction'] = createURL('import'); + $templateservice->loadTemplate($templatename, $tplVars); } + + function startElement($parser, $name, $attrs) { - global $depth, $status, $tplVars, $userservice; - - $bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService'); - $userservice =& ServiceFactory::getServiceInstance('UserService'); - - if ($name == 'POST') { - while(list($attrTitle, $attrVal) = each($attrs)) { - 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; - } - } - 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'); - } - - if ($bookmarkservice->addBookmark($bAddress, $bTitle, $bDescription, $status, $tags, $bDatetime, true, true)) - $tplVars['msg'] = T_('Bookmark imported.'); - else - $tplVars['error'] = T_('There was an error saving your bookmark. Please try again or contact the administrator.'); - } - } - $depth[$parser]++; + global $depth, $status, $tplVars, $userservice; + + $bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService'); + $userservice =& ServiceFactory::getServiceInstance('UserService'); + + if ($name == 'POST') { + while(list($attrTitle, $attrVal) = each($attrs)) { + 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; + } + } + 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'); + } + + if ($bookmarkservice->addBookmark($bAddress, $bTitle, $bDescription, $status, $tags, $bDatetime, true, true)) + $tplVars['msg'] = T_('Bookmark imported.'); + else + $tplVars['error'] = T_('There was an error saving your bookmark. Please try again or contact the administrator.'); + } + } + $depth[$parser]++; } function endElement($parser, $name) { - global $depth; - $depth[$parser]--; + global $depth; + $depth[$parser]--; } ?> -- cgit v1.2.3