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 +++----- www/api/export_gcs.php | 5 +++-- www/api/export_sioc.php | 2 +- www/api/opensearch.php | 2 +- www/api/posts_add.php | 5 ++--- www/api/posts_all.php | 5 ++--- www/api/posts_dates.php | 2 +- www/api/posts_delete.php | 5 ++--- www/api/posts_get.php | 2 +- www/api/posts_public.php | 2 +- www/api/posts_recent.php | 2 +- www/api/posts_update.php | 5 ++--- www/api/tags_get.php | 5 ++--- www/api/tags_rename.php | 5 ++--- 14 files changed, 24 insertions(+), 31 deletions(-) (limited to 'www/api') 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"; diff --git a/www/api/export_gcs.php b/www/api/export_gcs.php index 07bc726..9c0d85c 100644 --- a/www/api/export_gcs.php +++ b/www/api/export_gcs.php @@ -5,6 +5,7 @@ // Force HTTP authentication first! //require_once('httpauth.inc.php'); +$httpContentType = false; require_once '../www-header.php'; if($GLOBALS['enableGoogleCustomSearch'] == false) { @@ -39,7 +40,7 @@ $bookmarks =& $bookmarkservice->getBookmarks(0, NULL, NULL, $tag, NULL, getSortO // Set up the plain file and output all the posts. -header('Content-Type: text/plain'); +header('Content-Type: text/plain; charset=utf-8'); if(!$xml) { header('Content-Type: text/plain'); foreach($bookmarks['bookmarks'] as $row) { @@ -48,7 +49,7 @@ if(!$xml) { } } } else { - header('Content-Type: application/xml'); + header('Content-Type: text/xml'); echo ''."\n"; echo ' '."\n"; foreach($bookmarks['bookmarks'] as $row) { diff --git a/www/api/export_sioc.php b/www/api/export_sioc.php index ff1d1c0..8bdfd70 100644 --- a/www/api/export_sioc.php +++ b/www/api/export_sioc.php @@ -1,8 +1,8 @@ diff --git a/www/api/posts_add.php b/www/api/posts_add.php index c919ee7..59f7dce 100644 --- a/www/api/posts_add.php +++ b/www/api/posts_add.php @@ -11,8 +11,8 @@ // - No support for 'replace' variable // Force HTTP authentication -require_once('httpauth.inc.php'); -require_once '../www-header.php'; +$httpContentType = 'text/xml'; +require_once 'httpauth.inc.php'; /* Service creation: only useful services are created */ $bookmarkservice =SemanticScuttle_Service_Factory::get('Bookmark'); @@ -82,7 +82,6 @@ if (is_null($url) || is_null($description)) { } // Set up the XML file and output the result. -header('Content-Type: text/xml'); echo '\r\n"; echo ''; ?> \ No newline at end of file diff --git a/www/api/posts_all.php b/www/api/posts_all.php index f53f363..2d274f4 100644 --- a/www/api/posts_all.php +++ b/www/api/posts_all.php @@ -5,8 +5,8 @@ // - doesn't include the filtered tag as an attribute on the root element (we do) // Force HTTP authentication first! -require_once('httpauth.inc.php'); -require_once '../www-header.php'; +$httpContentType = 'text/xml'; +require_once 'httpauth.inc.php'; /* Service creation: only useful services are created */ $bookmarkservice =SemanticScuttle_Service_Factory::get('Bookmark'); @@ -22,7 +22,6 @@ else $bookmarks =& $bookmarkservice->getBookmarks(0, NULL, $userservice->getCurrentUserId(), $tag); // Set up the XML file and output all the posts. -header('Content-Type: text/xml'); echo '\r\n"; echo '\r\n"; diff --git a/www/api/posts_dates.php b/www/api/posts_dates.php index 7b1240f..508c46a 100644 --- a/www/api/posts_dates.php +++ b/www/api/posts_dates.php @@ -17,6 +17,7 @@ */ // Force HTTP authentication first! +$httpContentType = 'text/xml'; require_once 'httpauth.inc.php'; /* Service creation: only useful services are created */ @@ -36,7 +37,6 @@ $bookmarks = $bookmarkservice->getBookmarks( ); // Set up the XML file and output all the tags. -header('Content-Type: text/xml'); echo '\r\n"; echo '\r\n"; diff --git a/www/api/posts_delete.php b/www/api/posts_delete.php index 88e2584..a63cc62 100644 --- a/www/api/posts_delete.php +++ b/www/api/posts_delete.php @@ -7,8 +7,8 @@ // - doesn't set the Content-Type to text/xml (we do). // Force HTTP authentication first! -require_once('httpauth.inc.php'); -require_once '../www-header.php'; +$httpContentType = 'text/xml'; +require_once 'httpauth.inc.php'; /* Service creation: only useful services are created */ $bookmarkservice =SemanticScuttle_Service_Factory::get('Bookmark'); @@ -28,7 +28,6 @@ if (is_null($_REQUEST['url'])) { } // Set up the XML file and output the result. -header('Content-Type: text/xml'); echo '\r\n"; echo ''; ?> \ No newline at end of file diff --git a/www/api/posts_get.php b/www/api/posts_get.php index b020f51..c20f904 100644 --- a/www/api/posts_get.php +++ b/www/api/posts_get.php @@ -25,6 +25,7 @@ */ // Force HTTP authentication first! +$httpContentType = 'text/xml'; require_once 'httpauth.inc.php'; /* Service creation: only useful services are created */ @@ -54,7 +55,6 @@ $bookmarks = $bookmarkservice->getBookmarks( // Set up the XML file and output all the tags. -header('Content-Type: text/xml'); echo '\r\n"; echo '\r\n"; diff --git a/www/api/posts_public.php b/www/api/posts_public.php index 0c93ca2..4258550 100644 --- a/www/api/posts_public.php +++ b/www/api/posts_public.php @@ -6,6 +6,7 @@ // Force HTTP authentication first! //require_once('httpauth.inc.php'); +$httpContentType = 'text/xml'; require_once '../www-header.php'; /* Service creation: only useful services are created */ @@ -22,7 +23,6 @@ else $bookmarks =& $bookmarkservice->getBookmarks(0, NULL, NULL, $tag); // Set up the XML file and output all the posts. -header('Content-Type: text/xml'); echo '\r\n"; echo '\r\n"; diff --git a/www/api/posts_recent.php b/www/api/posts_recent.php index 46e46f1..6c71e22 100644 --- a/www/api/posts_recent.php +++ b/www/api/posts_recent.php @@ -22,6 +22,7 @@ $countDefault = 15; $countMax = 100; // Force HTTP authentication first! +$httpContentType = 'text/xml'; require_once 'httpauth.inc.php'; /* Service creation: only useful services are created */ @@ -54,7 +55,6 @@ $bookmarks = $bookmarkservice->getBookmarks( // Set up the XML file and output all the tags. -header('Content-Type: text/xml'); echo '\r\n"; echo '\r\n"; diff --git a/www/api/posts_update.php b/www/api/posts_update.php index 9152f26..4aeedc3 100644 --- a/www/api/posts_update.php +++ b/www/api/posts_update.php @@ -5,8 +5,8 @@ // - doesn't set the Content-Type to text/xml (we do). // Force HTTP authentication first! -require_once('httpauth.inc.php'); -require_once '../www-header.php'; +$httpContentType = 'text/xml'; +require_once 'httpauth.inc.php'; /* Service creation: only useful services are created */ $bookmarkservice =SemanticScuttle_Service_Factory::get('Bookmark'); @@ -17,7 +17,6 @@ $bookmarks =& $bookmarkservice->getBookmarks(0, 1, $userservice->getCurrentUserI // Set up the XML file and output all the tags. -header('Content-Type: text/xml'); echo '\r\n"; foreach($bookmarks['bookmarks'] as $row) { echo ''; diff --git a/www/api/tags_get.php b/www/api/tags_get.php index 85684d4..06a40d9 100644 --- a/www/api/tags_get.php +++ b/www/api/tags_get.php @@ -5,8 +5,8 @@ // - tags can't have spaces // Force HTTP authentication first! -require_once('httpauth.inc.php'); -require_once '../www-header.php'; +$httpContentType = 'text/xml'; +require_once 'httpauth.inc.php'; /* Service creation: only useful services are created */ $b2tservice =SemanticScuttle_Service_Factory::get('Bookmark2Tag'); @@ -16,7 +16,6 @@ $b2tservice =SemanticScuttle_Service_Factory::get('Bookmark2Tag'); $tags =& $b2tservice->getTags($userservice->getCurrentUserId()); // Set up the XML file and output all the tags. -header('Content-Type: text/xml'); echo '\r\n"; echo "\r\n"; foreach($tags as $row) { diff --git a/www/api/tags_rename.php b/www/api/tags_rename.php index 59ba8a4..cf56c83 100644 --- a/www/api/tags_rename.php +++ b/www/api/tags_rename.php @@ -5,8 +5,8 @@ // - oddly, returns an entirely different result () than the other API calls. // Force HTTP authentication first! -require_once('httpauth.inc.php'); -require_once '../www-header.php'; +$httpContentType = 'text/xml'; +require_once 'httpauth.inc.php'; /* Service creation: only useful services are created */ $b2tservice =SemanticScuttle_Service_Factory::get('Bookmark2Tag'); @@ -31,7 +31,6 @@ if (is_null($old) || is_null($new)) { } // Set up the XML file and output the result. -header('Content-Type: text/xml'); echo '\r\n"; echo ''. ($renamed ? 'done' : 'something went wrong') .''; ?> -- 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') 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') 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 From 7e6de50232ed7ba74ff7ea33f5fd5c838921bb1f Mon Sep 17 00:00:00 2001 From: cweiske Date: Sun, 28 Mar 2010 18:10:57 +0000 Subject: fix multiple tags in html export git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@704 b3834d28-1941-0410-a4f8-b48e95affb8f --- www/api/export_html.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'www/api') diff --git a/www/api/export_html.php b/www/api/export_html.php index 8d70927..731b7fb 100644 --- a/www/api/export_html.php +++ b/www/api/export_html.php @@ -27,7 +27,8 @@ $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']); + //$_GET vars have + replaced to " " automatically + $tag = str_replace(' ', '+', trim($_REQUEST['tag'])); } else { $tag = null; } -- cgit v1.2.3-54-g00ecf From ea0527fc83fbb04f89104836af8334e5476e04c4 Mon Sep 17 00:00:00 2001 From: cweiske Date: Sun, 28 Mar 2010 18:11:56 +0000 Subject: make export_html follow the "specs" a bit more and add format documentation url git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@705 b3834d28-1941-0410-a4f8-b48e95affb8f --- www/api/export_html.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'www/api') diff --git a/www/api/export_html.php b/www/api/export_html.php index 731b7fb..c7c8cf4 100644 --- a/www/api/export_html.php +++ b/www/api/export_html.php @@ -3,6 +3,9 @@ * Implements the del.icio.us API request for all a user's posts, * optionally filtered by tag. * + * Netscape bookmark file format is documented at + * http://msdn.microsoft.com/en-us/library/aa753582(VS.85).aspx + * * SemanticScuttle - your social bookmark manager. * * PHP version 5. @@ -46,7 +49,7 @@ echo ''; echo ''."\r\n"; echo 'Bookmarks'."\r\n"; echo '

Bookmarks for '. htmlspecialchars($currentUser->getUsername()) .''. (is_null($tag) ? '' : ' tag="'. htmlspecialchars($tag) .'"') ." from " . $sitename ."

\r\n"; -echo '

'."\r\n"; +echo '

'."\r\n"; @@ -68,9 +71,9 @@ foreach ($bookmarks['bookmarks'] as $row) { $taglist = 'system:unfiled'; } - echo "\t
" . filter($row['bTitle'], 'xml') ."\r\n"; + echo "\t
" . filter($row['bTitle'], 'xml') ."\r\n"; } -echo '

'; +echo '

'; ?> -- cgit v1.2.3-54-g00ecf