- Override privacy status on bookmark file import, if specified (i.e. Delicious)
authorMarcus Campbell <marcus.campbell@gmail.com>
Fri, 24 Dec 2010 04:53:51 +0000 (20:53 -0800)
committerMarcus Campbell <marcus.campbell@gmail.com>
Fri, 24 Dec 2010 04:53:51 +0000 (20:53 -0800)
- Set tags on bookmark file import, if specified (i.e. Delicious)

Signed-off-by: Marcus Campbell <marcus.campbell@gmail.com>
import.php
importNetscape.php
templates/bookmarks.tpl.php
templates/importNetscape.tpl.php

index 2af25d0e2a764e886e5bf7eb3a9b72838919ec0c..9f2972859b2dbe0168e980aacbcf1ff7acf11fd4 100644 (file)
@@ -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) {
index 97c0a4f14e7aa0697896f5ebe4a4b47f5fb2e177..f953ffc8a1f4ac0e324ec6dab155e332b71c237e 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
-Copyright (c) 2004 - 2006 Marcus Campbell
+Copyright (c) 2004 - 2010 Marcus Campbell
 http://scuttle.org/
 
 This program is free software; you can redistribute it and/or modify
@@ -19,18 +19,21 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 ***************************************************************************/
 
 require_once 'header.inc.php';
+
 $bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
-$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;
     }
 
     // File handle
@@ -38,47 +41,57 @@ if ($userservice->isLoggedOn() && sizeof($_FILES) > 0 && $_FILES['userfile']['si
     
     // Create link array
     preg_match_all('/<a\s+(.*?)\s*\/*>([^<]*)/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('"', '&quot;', 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('"', '&quot;', 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('"', '&quot;', 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('"', '&quot;', 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);
+}
index ab35787766c1a9c1b7ba7e89ff6b0c2e4a67ab8d..c79655ea229d87fb2c6e2ed31423275583beaf19 100644 (file)
@@ -10,16 +10,12 @@ if (count($bookmarks) > 0) {
 ?>
 
 <p id="sort">
-    <?php echo T_("Sort by:"); ?>
-    <a href="?sort=date_desc"><?php echo T_("Date"); ?></a><span> / </span>
-    <a href="?sort=title_asc"><?php echo T_("Title"); ?></a><span> / </span>
-    <?php
-    if (!isset($hash)) {
-    ?>
+  <?php echo T_("Sort by:"); ?>
+  <a href="?sort=date_desc"><?php echo T_("Date"); ?></a><span> / </span>
+  <a href="?sort=title_asc"><?php echo T_("Title"); ?></a><span> / </span>
+  <?php if (!isset($hash)): ?>
     <a href="?sort=url_asc"><?php echo T_("URL"); ?></a>
-    <?php
-    }
-    ?>
+  <?php endif; ?>
 </p>
 <ol<?php echo ($start > 0 ? ' start="'. ++$start .'"' : ''); ?> id="bookmarks">
 
index 627a5af10d96ba337c703312f22f8b36e2e7ece2..61459792b213dd5d9b3c66bc4927b63da609f90f 100644 (file)
@@ -1,6 +1,4 @@
-<?php
-$this->includeTemplate($GLOBALS['top_include']);
-?>
+<?php $this->includeTemplate($GLOBALS['top_include']); ?>
 
 <div id="bookmarks">
     <form id="import" enctype="multipart/form-data" action="<?php echo $formaction; ?>" method="post">
@@ -34,17 +32,15 @@ $this->includeTemplate($GLOBALS['top_include']);
         <li>
             <p><?php echo T_('Export your bookmarks from your browser to a file'); ?>:</p>
             <ul>
-                <li><?php echo T_('Internet Explorer: <kbd>File &gt; Import and Export... &gt; Export Favorites'); ?></kbd></li>
-                <li><?php echo T_('Mozilla Firefox: <kbd>Bookmarks &gt; Manage Bookmarks... &gt; File &gt; Export...'); ?></kbd></li>
-                <li><?php echo T_('Netscape: <kbd>Bookmarks &gt; Manage Bookmarks... &gt; Tools &gt; Export...'); ?></kbd></li>
+                <li><?php echo T_('Internet Explorer: <kbd>File &rarr; Import and Export&hellip; &rarr; Export Favorites</kbd>'); ?></li>
+                <li><?php echo T_('Mozilla Firefox: <kbd>Bookmarks &rarr; Manage Bookmarks&hellip; &rarr; File &rarr; Export&hellip;</kbd>'); ?></li>
+                <li><?php echo T_('Google Chrome: <kbd>Bookmark Manager &rarr; Organize &rarr; Export Bookmarks&hellip;</kbd>'); ?></li>
             </ul>
         </li>
-        <li><?php echo T_('Click <kbd>Browse...</kbd> to find the saved bookmark file on your computer. The maximum size the file can be is 1MB'); ?>.</li>
-        <li><?php echo T_('Select the default privacy setting for your imported bookmarks'); ?>.</li>
-        <li><?php echo T_('Click <kbd>Import</kbd> to start importing the bookmarks; it may take a minute'); ?>.</li>
+        <li><?php echo T_('Click <kbd>Browse&hellip;</kbd> to find the saved bookmark file on your computer. The maximum size the file can be is 1MB.'); ?></li>
+        <li><?php echo T_('Select the default privacy setting for your imported bookmarks.'); ?></li>
+        <li><?php echo T_('Click <kbd>Import</kbd> to start importing the bookmarks; it may take a minute.'); ?></li>
     </ol>
 </div>
 
-<?php
-$this->includeTemplate($GLOBALS['bottom_include']);
-?>
\ No newline at end of file
+<?php $this->includeTemplate($GLOBALS['bottom_include']); ?>
\ No newline at end of file

Benjamin Mako Hill || Want to submit a patch?