From 4d3d00ade282e27b765a64c86f6607f1a92af2c0 Mon Sep 17 00:00:00 2001 From: cweiske Date: Wed, 17 Mar 2010 20:11:21 +0000 Subject: Fix bug #2960663: do not send content-type headers twice for ajax/api scripts git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@690 b3834d28-1941-0410-a4f8-b48e95affb8f --- www/api/export_csv.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'www/api/export_csv.php') diff --git a/www/api/export_csv.php b/www/api/export_csv.php index 3f63692..b9cf497 100644 --- a/www/api/export_csv.php +++ b/www/api/export_csv.php @@ -2,8 +2,9 @@ // 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 '../www-header.php'; +$httpContentType = 'application/csv-tab-delimited-table'; +require_once 'httpauth.inc.php'; +header("Content-disposition: filename=exportBookmarks.csv"); /* Service creation: only useful services are created */ $bookmarkservice =SemanticScuttle_Service_Factory::get('Bookmark'); @@ -17,9 +18,6 @@ else // 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;charset=UTF-8"); -header("Content-disposition: filename=exportBookmarks.csv"); - //columns titles echo 'url;title;tags;description'; echo "\n"; -- cgit v1.2.3-54-g00ecf From 74dc9ea6a4e553f38a97928617074fd76793c783 Mon Sep 17 00:00:00 2001 From: cweiske Date: Sun, 28 Mar 2010 18:08:38 +0000 Subject: make export_csv support filtering to multiple tags git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@702 b3834d28-1941-0410-a4f8-b48e95affb8f --- tests/Api/ExportCsvTest.php | 61 +++++++++++++++++++++++++++++++++++++++++++++ www/api/export_csv.php | 15 +++++++---- 2 files changed, 71 insertions(+), 5 deletions(-) (limited to 'www/api/export_csv.php') diff --git a/tests/Api/ExportCsvTest.php b/tests/Api/ExportCsvTest.php index ee7db4b..18008e1 100644 --- a/tests/Api/ExportCsvTest.php +++ b/tests/Api/ExportCsvTest.php @@ -162,6 +162,67 @@ class Api_ExportCsvTest extends TestBaseApi + /** + * Test CSV export with tag filter + */ + public function testTagFilter() + { + list($req, $uid) = $this->getAuthRequest('?tag=tag1'); + $this->addBookmark( + $uid, 'http://example.org/tag-1', 0, + array('unittest', 'tag1') + ); + $this->addBookmark( + $uid, 'http://example.org/tag-2', 0, + array('unittest', 'tag2') + ); + $this->addBookmark( + $uid, 'http://example.org/tag-3', 0, + array('unittest', 'tag1', 'tag2') + ); + + $body = $req->send()->getBody(); + $csv = $this->getCsvArray($body); + + $this->assertEquals(3, count($csv)); + $this->assertCsvHeader($csv); + + $this->assertEquals('http://example.org/tag-1', $csv[1][0]); + $this->assertEquals('http://example.org/tag-3', $csv[2][0]); + } + + + + /** + * Test CSV export with tag filter for multiple tags + */ + public function testTagFilterMultiple() + { + list($req, $uid) = $this->getAuthRequest('?tag=tag1+tag2'); + $this->addBookmark( + $uid, 'http://example.org/tag-1', 0, + array('unittest', 'tag1') + ); + $this->addBookmark( + $uid, 'http://example.org/tag-2', 0, + array('unittest', 'tag2') + ); + $this->addBookmark( + $uid, 'http://example.org/tag-3', 0, + array('unittest', 'tag1', 'tag2') + ); + + $body = $req->send()->getBody(); + $csv = $this->getCsvArray($body); + + $this->assertEquals(2, count($csv)); + $this->assertCsvHeader($csv); + + $this->assertEquals('http://example.org/tag-3', $csv[1][0]); + } + + + /** * Asserts that the CSV array contains the correct header * diff --git a/www/api/export_csv.php b/www/api/export_csv.php index b9cf497..43951ec 100644 --- a/www/api/export_csv.php +++ b/www/api/export_csv.php @@ -10,13 +10,18 @@ header("Content-disposition: filename=exportBookmarks.csv"); $bookmarkservice =SemanticScuttle_Service_Factory::get('Bookmark'); // Check to see if a tag was specified. -if (isset($_REQUEST['tag']) && (trim($_REQUEST['tag']) != '')) - $tag = trim($_REQUEST['tag']); -else - $tag = NULL; +if (isset($_REQUEST['tag']) && (trim($_REQUEST['tag']) != '')) { + //$_GET vars have + replaced to " " automatically + $tag = str_replace(' ', '+', 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()); +$bookmarks = $bookmarkservice->getBookmarks( + 0, null, $userservice->getCurrentUserId(), + $tag, null, getSortOrder() +); //columns titles echo 'url;title;tags;description'; -- cgit v1.2.3-54-g00ecf From ccbc63aec4869f64fb68706a6d687aa665a60c9c Mon Sep 17 00:00:00 2001 From: cweiske Date: Sun, 28 Mar 2010 18:09:59 +0000 Subject: test that public bookmarks of other people are not exported via csv git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@703 b3834d28-1941-0410-a4f8-b48e95affb8f --- tests/Api/ExportCsvTest.php | 5 +++++ www/api/export_csv.php | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) (limited to 'www/api/export_csv.php') diff --git a/tests/Api/ExportCsvTest.php b/tests/Api/ExportCsvTest.php index 18008e1..2bff8a5 100644 --- a/tests/Api/ExportCsvTest.php +++ b/tests/Api/ExportCsvTest.php @@ -140,6 +140,11 @@ class Api_ExportCsvTest extends TestBaseApi $this->addBookmark( null, 'http://example.org/testBookmarks-private2', 2 ); + //public bookmark from other people that should not be + // exported, too + $this->addBookmark( + null, 'http://example.org/testBookmarks-other', 0 + ); $body = $req->send()->getBody(); $csv = $this->getCsvArray($body); diff --git a/www/api/export_csv.php b/www/api/export_csv.php index 43951ec..bb469b1 100644 --- a/www/api/export_csv.php +++ b/www/api/export_csv.php @@ -1,5 +1,18 @@ + * @author Christian Weiske + * @author Eric Dane + * @license GPL http://www.gnu.org/licenses/gpl.html + * @link http://sourceforge.net/projects/semanticscuttle + */ // Force HTTP authentication first! $httpContentType = 'application/csv-tab-delimited-table'; -- cgit v1.2.3-54-g00ecf