From 616df7459a1262dc55320ee60cc74dae9d878ab3 Mon Sep 17 00:00:00 2001 From: Marcus Campbell Date: Thu, 23 Dec 2010 20:53:51 -0800 Subject: [PATCH] - Override privacy status on bookmark file import, if specified (i.e. Delicious) - Set tags on bookmark file import, if specified (i.e. Delicious) Signed-off-by: Marcus Campbell --- import.php | 22 ++++---- importNetscape.php | 91 ++++++++++++++++++-------------- templates/bookmarks.tpl.php | 14 ++--- templates/importNetscape.tpl.php | 20 +++---- 4 files changed, 78 insertions(+), 69 deletions(-) diff --git a/import.php b/import.php index 2af25d0..9f29728 100644 --- a/import.php +++ b/import.php @@ -19,17 +19,20 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ***************************************************************************/ require_once 'header.inc.php'; -$userservice =& ServiceFactory::getServiceInstance('UserService'); + +$userservice =& ServiceFactory::getServiceInstance('UserService'); $templateservice =& ServiceFactory::getServiceInstance('TemplateService'); + $tplVars = array(); if ($userservice->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; + $status = intval($_POST['status']); + } + else { + $status = 2; } $depth = array(); @@ -48,11 +51,12 @@ if ($userservice->isLoggedOn() && sizeof($_FILES) > 0 && $_FILES['userfile']['si } xml_parser_free($xml_parser); header('Location: '. createURL('bookmarks', $userinfo[$userservice->getFieldName('username')])); -} else { - $templatename = 'importDelicious.tpl'; - $tplVars['subtitle'] = T_('Import Bookmarks from del.icio.us'); - $tplVars['formaction'] = createURL('import'); - $templateservice->loadTemplate($templatename, $tplVars); +} +else { + $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) { diff --git a/importNetscape.php b/importNetscape.php index 97c0a4f..f953ffc 100644 --- a/importNetscape.php +++ b/importNetscape.php @@ -1,6 +1,6 @@ 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; + $status = intval($_POST['status']); + } + else { + $status = 2; } // File handle @@ -38,47 +41,57 @@ if ($userservice->isLoggedOn() && sizeof($_FILES) > 0 && $_FILES['userfile']['si // Create link array preg_match_all('/([^<]*)/si', $html, $matches); - $links = $matches[1]; + $links = $matches[1]; $titles = $matches[2]; $size = count($links); for ($i = 0; $i < $size; $i++) { - $attributes = preg_split('/\s+/s', $links[$i]); - foreach ($attributes as $attribute) { - $att = preg_split('/\s*=\s*/s', $attribute, 2); - $attrTitle = $att[0]; - $attrVal = eregi_replace('"', '"', preg_replace('/([\'"]?)(.*)\1/', '$2', $att[1])); - switch ($attrTitle) { - case "HREF": - $bAddress = $attrVal; - break; - case "ADD_DATE": - $bDatetime = gmdate('Y-m-d H:i:s', $attrVal); - break; - } - } - $bTitle = eregi_replace('"', '"', trim($titles[$i])); + $bTags = ''; + $bStatus = $status; - if ($bookmarkservice->bookmarkExists($bAddress, $userservice->getCurrentUserId())) { - $tplVars['error'] = T_('You have already submitted this bookmark.'); - } else { - // 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'); - } + $attributes = preg_split('/\s+/s', $links[$i]); + foreach ($attributes as $attribute) { + $att = preg_split('/\s*=\s*/s', $attribute, 2); + $attrTitle = $att[0]; + $attrVal = str_replace('"', '"', preg_replace('/([\'"]?)(.*)\1/', '$2', $att[1])); + switch ($attrTitle) { + case 'HREF': + $bAddress = $attrVal; + break; + case 'ADD_DATE': + $bDatetime = gmdate('Y-m-d H:i:s', $attrVal); + break; + case 'PRIVATE': + $bStatus = (intval($attrVal) == 1) ? 2 : $status; + break; + case 'TAGS': + $bTags = strtolower($attrVal); + break; + } + } + $bTitle = str_replace('"', '"', trim($titles[$i])); - if ($bookmarkservice->addBookmark($bAddress, $bTitle, NULL, $status, NULL, $bDatetime, false, true)) { - $tplVars['msg'] = T_('Bookmark imported.'); - } else { - $tplVars['error'] = T_('There was an error saving your bookmark. Please try again or contact the administrator.'); - } + if ($bookmarkservice->bookmarkExists($bAddress, $userservice->getCurrentUserId())) { + $tplVars['error'] = T_('You have already submitted this bookmark.'); + } else { + // 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, NULL, $bStatus, $bTags, $bDatetime, false, true)) { + $tplVars['msg'] = T_('Bookmark imported.'); + } + else { + $tplVars['error'] = T_('There was an error saving your bookmark. Please try again or contact the administrator.'); + } + } } header('Location: '. createURL('bookmarks', $userinfo[$userservice->getFieldName('username')])); -} else { - $templatename = 'importNetscape.tpl'; - $tplVars['subtitle'] = T_('Import Bookmarks from Browser File'); - $tplVars['formaction'] = createURL('importNetscape'); - $templateservice->loadTemplate($templatename, $tplVars); } -?> +else { + $templatename = 'importNetscape.tpl'; + $tplVars['subtitle'] = T_('Import Bookmarks from Browser File'); + $tplVars['formaction'] = createURL('importNetscape'); + $templateservice->loadTemplate($templatename, $tplVars); +} diff --git a/templates/bookmarks.tpl.php b/templates/bookmarks.tpl.php index ab35787..c79655e 100644 --- a/templates/bookmarks.tpl.php +++ b/templates/bookmarks.tpl.php @@ -10,16 +10,12 @@ if (count($bookmarks) > 0) { ?>

- - / - / - + + / + / + - +

0 ? ' start="'. ++$start .'"' : ''); ?> id="bookmarks"> diff --git a/templates/importNetscape.tpl.php b/templates/importNetscape.tpl.php index 627a5af..6145979 100644 --- a/templates/importNetscape.tpl.php +++ b/templates/importNetscape.tpl.php @@ -1,6 +1,4 @@ -includeTemplate($GLOBALS['top_include']); -?> +includeTemplate($GLOBALS['top_include']); ?>
@@ -34,17 +32,15 @@ $this->includeTemplate($GLOBALS['top_include']);
  • :

      -
    • File > Import and Export... > Export Favorites'); ?>
    • -
    • Bookmarks > Manage Bookmarks... > File > Export...'); ?>
    • -
    • Bookmarks > Manage Bookmarks... > Tools > Export...'); ?>
    • +
    • File → Import and Export… → Export Favorites'); ?>
    • +
    • Bookmarks → Manage Bookmarks… → File → Export…'); ?>
    • +
    • Bookmark Manager → Organize → Export Bookmarks…'); ?>
  • -
  • Browse... to find the saved bookmark file on your computer. The maximum size the file can be is 1MB'); ?>.
  • -
  • .
  • -
  • Import to start importing the bookmarks; it may take a minute'); ?>.
  • +
  • Browse… to find the saved bookmark file on your computer. The maximum size the file can be is 1MB.'); ?>
  • +
  • +
  • Import to start importing the bookmarks; it may take a minute.'); ?>
  • -includeTemplate($GLOBALS['bottom_include']); -?> \ No newline at end of file +includeTemplate($GLOBALS['bottom_include']); ?> \ No newline at end of file -- 2.39.2