summaryrefslogtreecommitdiff
path: root/api/export_csv.php
diff options
context:
space:
mode:
authormensonge <mensonge@b3834d28-1941-0410-a4f8-b48e95affb8f>2009-05-05 13:27:07 +0000
committermensonge <mensonge@b3834d28-1941-0410-a4f8-b48e95affb8f>2009-05-05 13:27:07 +0000
commitc3d67c16be0ff84d5502827e4095c213e655515a (patch)
tree44ff195410b0151e5ea06c867287ffd37dca4841 /api/export_csv.php
parentc12348f5e7ef8bd89ec70584abf539e963631ea2 (diff)
downloadsemanticscuttle-c3d67c16be0ff84d5502827e4095c213e655515a.tar.gz
semanticscuttle-c3d67c16be0ff84d5502827e4095c213e655515a.tar.bz2
New Feature: export user's bookmarks into CSV format for import into spreadsheet tools
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@316 b3834d28-1941-0410-a4f8-b48e95affb8f
Diffstat (limited to 'api/export_csv.php')
-rw-r--r--api/export_csv.php47
1 files changed, 47 insertions, 0 deletions
diff --git a/api/export_csv.php b/api/export_csv.php
new file mode 100644
index 0000000..d9d824b
--- /dev/null
+++ b/api/export_csv.php
@@ -0,0 +1,47 @@
+<?php
+// Export in CSV format in order to allow the import into a spreadsheet tool like Excel
+
+// Force HTTP authentication first!
+require_once('httpauth.inc.php');
+require_once('../header.inc.php');
+
+/* Service creation: only useful services are created */
+$bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
+
+// Check to see if a tag was specified.
+if (isset($_REQUEST['tag']) && (trim($_REQUEST['tag']) != ''))
+ $tag = trim($_REQUEST['tag']);
+else
+ $tag = NULL;
+
+// Get the posts relevant to the passed-in variables.
+$bookmarks =& $bookmarkservice->getBookmarks(0, NULL, $userservice->getCurrentUserId(), $tag, NULL, getSortOrder());
+
+header("Content-Type: application/csv-tab-delimited-table");
+header("Content-disposition: filename=exportBookmarks.csv");
+
+//columns titles
+echo 'url,title,tags,description';
+echo "\n";
+
+foreach($bookmarks['bookmarks'] as $row) {
+ if (is_null($row['bDescription']) || (trim($row['bDescription']) == ''))
+ $description = '';
+ else
+ $description = filter($row['bDescription'], 'xml');
+
+ $taglist = '';
+ if (count($row['tags']) > 0) {
+ foreach($row['tags'] as $tag)
+ $taglist .= convertTag($tag) .',';
+ $taglist = substr($taglist, 0, -1);
+ } else {
+ $taglist = 'system:unfiled';
+ }
+
+ echo '"'.filter($row['bAddress'], 'xml') .'","'. filter($row['bTitle'], 'xml') .'","'. filter($taglist, 'xml') .'","'. $description .'"';
+ echo "\n";
+}
+
+
+?>