]> gitweb.fluxo.info Git - semanticscuttle.git/commitdiff
New Feature: export user's bookmarks into CSV format for import into spreadsheet...
authormensonge <mensonge@b3834d28-1941-0410-a4f8-b48e95affb8f>
Tue, 5 May 2009 13:27:07 +0000 (13:27 +0000)
committermensonge <mensonge@b3834d28-1941-0410-a4f8-b48e95affb8f>
Tue, 5 May 2009 13:27:07 +0000 (13:27 +0000)
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@316 b3834d28-1941-0410-a4f8-b48e95affb8f

api/.htaccess
api/export_csv.php [new file with mode: 0644]

index 95532548dab5417713ad33594c05785adbe2fddb..dc20db5d372b3aa00ff6924756f4f9c3e0c6c64d 100644 (file)
@@ -13,6 +13,7 @@ RewriteRule ^posts/update posts_update.php
 RewriteRule ^posts/add posts_add.php
 RewriteRule ^posts/delete posts_delete.php
 RewriteRule ^export/html export_html.php
+RewriteRule ^export/csv export_csv.php
 
 RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization},L]
 </IfModule>
diff --git a/api/export_csv.php b/api/export_csv.php
new file mode 100644 (file)
index 0000000..d9d824b
--- /dev/null
@@ -0,0 +1,47 @@
+<?php\r
+// Export in CSV format in order to allow the import into a spreadsheet tool like Excel\r
+\r
+// Force HTTP authentication first!
+require_once('httpauth.inc.php');\r
+require_once('../header.inc.php');\r
+
+/* Service creation: only useful services are created */\r
+$bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');\r
+\r
+// Check to see if a tag was specified.\r
+if (isset($_REQUEST['tag']) && (trim($_REQUEST['tag']) != ''))\r
+    $tag = trim($_REQUEST['tag']);\r
+else\r
+    $tag = NULL;\r
+\r
+// Get the posts relevant to the passed-in variables.\r
+$bookmarks =& $bookmarkservice->getBookmarks(0, NULL, $userservice->getCurrentUserId(), $tag, NULL, getSortOrder());\r
+\r
+header("Content-Type: application/csv-tab-delimited-table");
+header("Content-disposition: filename=exportBookmarks.csv");\r
+\r
+//columns titles
+echo 'url,title,tags,description';
+echo "\n";\r
+\r
+foreach($bookmarks['bookmarks'] as $row) {\r
+    if (is_null($row['bDescription']) || (trim($row['bDescription']) == ''))\r
+        $description = '';\r
+    else\r
+        $description = filter($row['bDescription'], 'xml');\r
+\r
+    $taglist = '';\r
+    if (count($row['tags']) > 0) {\r
+        foreach($row['tags'] as $tag)\r
+            $taglist .= convertTag($tag) .',';\r
+        $taglist = substr($taglist, 0, -1);\r
+    } else {\r
+        $taglist = 'system:unfiled';\r
+    }\r
+\r
+    echo '"'.filter($row['bAddress'], 'xml') .'","'. filter($row['bTitle'], 'xml') .'","'. filter($taglist, 'xml') .'","'. $description .'"';
+    echo "\n";\r
+}\r
+\r
+\r
+?>\r