From 65bd4bfab86fc47be3ce125640ebd49163f24f4b Mon Sep 17 00:00:00 2001 From: bretticvs Date: Tue, 15 Mar 2011 07:53:39 +0100 Subject: [PATCH] Updates for feature request 3164348: Make default privacy configurable. --- data/config.default.php | 17 +++++++++++++++++ data/config.php.dist | 22 ++++++++++++++++++++++ data/templates/bookmarks.tpl.php | 2 +- tests/BookmarkTest.php | 24 ++++++++++++++++++++++++ www/api/posts_add.php | 2 +- www/bookmarks.php | 4 ++-- www/edit.php | 2 +- www/import.php | 4 ++-- www/importNetscape.php | 4 ++-- 9 files changed, 72 insertions(+), 9 deletions(-) diff --git a/data/config.default.php b/data/config.default.php index bd67c7b..cd611f1 100644 --- a/data/config.default.php +++ b/data/config.default.php @@ -14,6 +14,13 @@ * @link http://sourceforge.net/projects/semanticscuttle/ */ +/** + * Array for defaults. + * + * @var array + */ +$defaults = array(); + /*************************************************** * HTML output configuration @@ -493,6 +500,16 @@ $votingMode = 2; */ $hideBelowVoting = null; +/** + * Default privacy setting for bookmarks: + * 0 - Public + * 1 - Shared with Watchlist + * 2 - Private + * + * @var integer + */ +$defaults['privacy'] = 0; + /**************************** * Website Thumbnails diff --git a/data/config.php.dist b/data/config.php.dist index c135e8e..0f849e2 100644 --- a/data/config.php.dist +++ b/data/config.php.dist @@ -7,6 +7,13 @@ * See config.default.inc.php for more options. */ +/** + * Array for defaults. + * + * @var array + */ +$defaults = array(); + /** * The name of this site. * @@ -116,6 +123,21 @@ $adminemail = 'admin@example.org'; $admin_users = array(); +/*************************************************** + * Bookmarks + */ + +/** + * Default privacy setting for bookmarks. + * 0 - Public + * 1 - Shared with Watchlist + * 2 - Private + * + * @var integer + */ +$defaults['privacy'] = 0; + + /** * You have completed the basic configuration! * More options can be found in config.default.php. diff --git a/data/templates/bookmarks.tpl.php b/data/templates/bookmarks.tpl.php index e32d3c9..44dfe90 100644 --- a/data/templates/bookmarks.tpl.php +++ b/data/templates/bookmarks.tpl.php @@ -256,7 +256,7 @@ if ($currenttag!= '') { foreach ($bookmarks as $key => &$row) { switch ($row['bStatus']) { case 0: - $access = ''; + $access = ' public'; break; case 1: $access = ' shared'; diff --git a/tests/BookmarkTest.php b/tests/BookmarkTest.php index f54fe9a..aa0b8c3 100644 --- a/tests/BookmarkTest.php +++ b/tests/BookmarkTest.php @@ -1343,6 +1343,30 @@ class BookmarkTest extends TestBase } + /** + * Test that the default privacy setting in + * $GLOBALS['defaults']['privacy'] is used + * as expected. + * + * @return void + */ + public function testDefaultPrivacy() + { + $GLOBALS['defaults']['privacy'] = 1; + $uid = $this->addUser(); + $this->us->setCurrentUserId($uid); + $bid = $this->bs->addBookmark('http://www.somedomain.com', 'mybookmark1', 'descr1', 'privatenote1', $GLOBALS['defaults']['privacy'], array()); + $bm = $this->bs->getBookmark($bid); + $this->assertEquals('1', $bm['bStatus']); + $GLOBALS['defaults']['privacy'] = 2; + $uid = $this->addUser(); + $this->us->setCurrentUserId($uid); + $bid = $this->bs->addBookmark('http://www.anotherdomain.com', 'mybookmark2', 'descr2', 'privatenote2', $GLOBALS['defaults']['privacy'], array()); + $bm = $this->bs->getBookmark($bid); + $this->assertEquals('2', $bm['bStatus']); + }//end function testDefaultPrivacy + + } diff --git a/www/api/posts_add.php b/www/api/posts_add.php index 7f9dc59..80d6515 100644 --- a/www/api/posts_add.php +++ b/www/api/posts_add.php @@ -81,7 +81,7 @@ if (isset($_REQUEST['dt']) && (trim($_REQUEST['dt']) != '')) { $replace = isset($_REQUEST['replace']) && ($_REQUEST['replace'] == 'yes'); -$status = 0; +$status = $GLOBALS['defaults']['privacy']; if (isset($_REQUEST['status'])) { $status_str = trim($_REQUEST['status']); if (is_numeric($status_str)) { diff --git a/www/bookmarks.php b/www/bookmarks.php index 5241481..d4fe051 100644 --- a/www/bookmarks.php +++ b/www/bookmarks.php @@ -185,7 +185,7 @@ if ($templatename == 'editbookmark.tpl') { 'bDescription' => stripslashes(POST_DESCRIPTION), 'bPrivateNote' => stripslashes(POST_PRIVATENOTE), 'tags' => (POST_TAGS ? explode(',', stripslashes(POST_TAGS)) : array()), - 'bStatus' => 0, + 'bStatus' => $GLOBALS['defaults']['privacy'], ); $tplVars['tags'] = POST_TAGS; } else { @@ -201,7 +201,7 @@ if ($templatename == 'editbookmark.tpl') { 'bDescription' => stripslashes(GET_DESCRIPTION), 'bPrivateNote' => stripslashes(GET_PRIVATENOTE), 'tags' => (GET_TAGS ? explode(',', stripslashes(GET_TAGS)) : array()), - 'bStatus' => 0 + 'bStatus' => $GLOBALS['defaults']['privacy'] ); } diff --git a/www/edit.php b/www/edit.php index fbea163..cbfa30b 100644 --- a/www/edit.php +++ b/www/edit.php @@ -33,7 +33,7 @@ isset($_POST['title']) ? define('POST_TITLE', $_POST['title']): define('POST_TIT isset($_POST['address']) ? define('POST_ADDRESS', $_POST['address']): define('POST_ADDRESS', ''); isset($_POST['description']) ? define('POST_DESCRIPTION', $_POST['description']): define('POST_DESCRIPTION', ''); isset($_POST['privateNote']) ? define('POST_PRIVATENOTE', $_POST['privateNote']): define('POST_PRIVATENOTE', ''); -isset($_POST['status']) ? define('POST_STATUS', $_POST['status']): define('POST_STATUS', ''); +isset($_POST['status']) ? define('POST_STATUS', $_POST['status']): define('POST_STATUS', $GLOBALS['defaults']['privacy']); isset($_POST['tags']) ? define('POST_TAGS', $_POST['tags']): define('POST_TAGS', ''); isset($_GET['popup']) ? define('GET_POPUP', $_GET['popup']): define('GET_POPUP', ''); diff --git a/www/import.php b/www/import.php index 5263aba..3aa2714 100644 --- a/www/import.php +++ b/www/import.php @@ -27,7 +27,7 @@ require_once 'www-header.php'; /* Managing all possible inputs */ // First input is $_FILES // Other inputs -isset($_POST['status']) ? define('POST_STATUS', $_POST['status']): define('POST_STATUS', ''); +isset($_POST['status']) ? define('POST_STATUS', $_POST['status']): define('POST_STATUS', $GLOBALS['defaults']['privacy']); if ($userservice->isLoggedOn() && sizeof($_FILES) > 0 && $_FILES['userfile']['size'] > 0) { @@ -36,7 +36,7 @@ if ($userservice->isLoggedOn() && sizeof($_FILES) > 0 && $_FILES['userfile']['si if (is_numeric(POST_STATUS)) { $status = intval(POST_STATUS); } else { - $status = 2; + $status = $GLOBALS['defaults']['privacy']; } $depth = array(); diff --git a/www/importNetscape.php b/www/importNetscape.php index e23c156..b476c40 100644 --- a/www/importNetscape.php +++ b/www/importNetscape.php @@ -28,7 +28,7 @@ $bookmarkservice =SemanticScuttle_Service_Factory::get('Bookmark'); /* Managing all possible inputs */ // First input is $_FILES // Other inputs -isset($_POST['status']) ? define('POST_STATUS', $_POST['status']): define('POST_STATUS', ''); +isset($_POST['status']) ? define('POST_STATUS', $_POST['status']): define('POST_STATUS', $GLOBALS['defaults']['privacy']); $countImportedBookmarks = 0; $tplVars['msg'] = ''; @@ -39,7 +39,7 @@ if ($userservice->isLoggedOn() && sizeof($_FILES) > 0 && $_FILES['userfile']['si if (is_numeric(POST_STATUS)) { $status = intval(POST_STATUS); } else { - $status = 2; + $status = $GLOBALS['defaults']['privacy']; } // File handle