From ec345f7a1343769abdf3f5920a0732b24726b733 Mon Sep 17 00:00:00 2001
From: Mark Pemberton
Date: Fri, 13 May 2011 14:26:51 -0400
Subject: new privatekey2 branch with privatekey changes
---
src/SemanticScuttle/Model/User.php | 26 +++-
src/SemanticScuttle/Service/Bookmark.php | 2 +-
src/SemanticScuttle/Service/User.php | 211 ++++++++++++++++++++++++++-----
3 files changed, 205 insertions(+), 34 deletions(-)
(limited to 'src/SemanticScuttle')
diff --git a/src/SemanticScuttle/Model/User.php b/src/SemanticScuttle/Model/User.php
index 500f5b1..3aa617b 100644
--- a/src/SemanticScuttle/Model/User.php
+++ b/src/SemanticScuttle/Model/User.php
@@ -35,6 +35,7 @@ class SemanticScuttle_Model_User
var $content;
var $datetime;
var $isAdmin;
+ var $privateKey;
/**
* Create a new user object
@@ -68,6 +69,29 @@ class SemanticScuttle_Model_User
return $this->username;
}
+ /**
+ * Returns private key
+ *
+ * @param boolean return sanitized value which basically drops
+ * leading dash if exists
+ *
+ * @return string private key
+ */
+ public function getPrivateKey($sanitized = false)
+ {
+ // Look for value only if not already set
+ if (!isset($this->privateKey)) {
+ $us = SemanticScuttle_Service_Factory::get('User');
+ $user = $us->getUser($this->id);
+ $this->privateKey = $user['privateKey'];
+ }
+ if ($sanitized == true) {
+ return substr($this->privateKey, -32);
+ } else {
+ return $this->privateKey;
+ }
+ }
+
/**
* Returns full user name as specified in the profile.
*
@@ -182,4 +206,4 @@ class SemanticScuttle_Model_User
}
}
-?>
\ No newline at end of file
+?>
diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php
index 919ca7a..e836cd8 100644
--- a/src/SemanticScuttle/Service/Bookmark.php
+++ b/src/SemanticScuttle/Service/Bookmark.php
@@ -717,7 +717,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
// All public bookmarks, user's own bookmarks
// and any shared with user
$privacy = ' AND ((B.bStatus = 0) OR (B.uId = '. $sId .')';
- $watchnames = $userservice->getWatchNames($sId, true);
+ $watchnames = $userservice->getWatchNames($sId);
foreach ($watchnames as $watchuser) {
$privacy .= ' OR (U.username = "'. $watchuser .'" AND B.bStatus = 1)';
}
diff --git a/src/SemanticScuttle/Service/User.php b/src/SemanticScuttle/Service/User.php
index 09a2cb1..c3633de 100644
--- a/src/SemanticScuttle/Service/User.php
+++ b/src/SemanticScuttle/Service/User.php
@@ -48,9 +48,10 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
protected $currentuser = null;
protected $fields = array(
- 'primary' => 'uId',
- 'username' => 'username',
- 'password' => 'password'
+ 'primary' => 'uId',
+ 'username' => 'username',
+ 'password' => 'password',
+ 'privatekey' => 'privatekey'
);
protected $profileurl;
@@ -215,6 +216,18 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
return $this->_getuser($this->getFieldName('username'), $username);
}
+ /**
+ * Returns user row from database.
+ *
+ * @param string $privatekey Private Key
+ *
+ * @return array User array from database, false if no user was found
+ */
+ public function getUserByPrivateKey($privatekey)
+ {
+ return $this->_getuser($this->getFieldName('privatekey'), $privatekey);
+ }
+
function getObjectUserByUsername($username) {
$user = $this->_getuser($this->getFieldName('username'), $username);
if($user != false) {
@@ -279,6 +292,22 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
return ($this->getCurrentUserId() !== false);
}
+ /**
+ * Tells you if the private key is enabled and valid
+ *
+ * @param string $privateKey Private Key
+ *
+ * @return boolean True if enabled and valid
+ */
+ public function isPrivateKeyValid($privateKey)
+ {
+ // check length of private key
+ if (strlen($privateKey) == 32) {
+ return true;
+ }
+ return false;
+ }
+
/**
* Returns the current user object
*
@@ -293,7 +322,7 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
{
if (!is_null($newval)) {
//internal use only: reset currentuser
- $currentuser = $newval;
+ $this->currentuser = $newval;
} else if ($refresh || !isset($this->currentuser)) {
if ($id = $this->getCurrentUserId()) {
$this->currentuser = $this->getUser($id);
@@ -509,6 +538,47 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
}
}
+ /**
+ * Try to authenticate via the privatekey
+ *
+ * @param string $privatekey Private Key
+ *
+ * @return boolean true if the user could be authenticated,
+ * false if not.
+ */
+ public function loginPrivateKey($privatekey)
+ {
+ /* Check if private key valid and enabled */
+ if (!$this->isPrivateKeyValid($privatekey)) {
+ return false;
+ }
+
+ $query = 'SELECT '. $this->getFieldName('primary') .' FROM '
+ . $this->getTableName() .' WHERE '
+ . $this->getFieldName('privatekey') .' = "'
+ . $this->db->sql_escape($privatekey) .'"';
+
+ if (!($dbresult = $this->db->sql_query($query))) {
+ message_die(
+ GENERAL_ERROR,
+ 'Could not get user',
+ '', __LINE__, __FILE__, $query, $this->db
+ );
+ return false;
+ }
+
+ $row = $this->db->sql_fetchrow($dbresult);
+ $this->db->sql_freeresult($dbresult);
+
+ if ($row) {
+ $id = $_SESSION[$this->getSessionKey()]
+ = $row[$this->getFieldName('primary')];
+ return true;
+ } else {
+ return false;
+ }
+ }
+
/**
* Logs the user off
*
@@ -519,7 +589,8 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
@setcookie($this->getCookiekey(), '', time() - 1, '/');
unset($_COOKIE[$this->getCookiekey()]);
session_unset();
- $this->getCurrentUser(TRUE, false);
+ $this->currentuserId = null;
+ $this->currentuser = null;
}
function getWatchlist($uId) {
@@ -646,24 +717,26 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
* No checks are done in here - you ought to have checked
* everything before calling this method!
*
- * @param string $username Username to use
- * @param string $password Password to use
- * @param string $email Email to use
+ * @param string $username Username to use
+ * @param string $password Password to use
+ * @param string $email Email to use
+ * @param string $privateKey Key for RSS auth
*
* @return mixed Integer user ID if all is well,
* boolean false if an error occured
*/
- public function addUser($username, $password, $email)
+ public function addUser($username, $password, $email, $privateKey = null)
{
// Set up the SQL UPDATE statement.
$datetime = gmdate('Y-m-d H:i:s', time());
$password = $this->sanitisePassword($password);
$values = array(
- 'username' => $username,
- 'password' => $password,
- 'email' => $email,
- 'uDatetime' => $datetime,
- 'uModified' => $datetime
+ 'username' => $username,
+ 'password' => $password,
+ 'email' => $email,
+ 'uDatetime' => $datetime,
+ 'uModified' => $datetime,
+ 'privateKey' => $privateKey
);
$sql = 'INSERT INTO '. $this->getTableName()
. ' '. $this->db->sql_build_array('INSERT', $values);
@@ -687,40 +760,64 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
/**
* Updates the given user
*
- * @param integer $uId ID of user to change
- * @param string $password Password to use
- * @param string $name Realname to use
- * @param string $email Email to use
- * @param string $homepage User's homepage
- * @param string $uContent User note
+ * @param integer $uId ID of user to change
+ * @param string $password Password to use
+ * @param string $name Realname to use
+ * @param string $email Email to use
+ * @param string $homepage User's homepage
+ * @param string $uContent User note
+ * @param string $privateKey RSS Private Key
+ * @param boolean $enablePrivateKey RSS Private Key Flag
*
* @return boolean True when all is well, false if not
*/
public function updateUser(
- $uId, $password, $name, $email, $homepage, $uContent
+ $uId, $password, $name, $email, $homepage, $uContent,
+ $privateKey = null, $enablePrivateKey = false
) {
if (!is_numeric($uId)) {
return false;
}
+ // prepend '-' to privateKey if disabled
+ if ($privateKey != null && strlen($privateKey) == 32
+ && $enablePrivateKey == false
+ ) {
+ $privateKey = '-' . $privateKey;
+ }
+
+ // remove '-' from privateKey if enabling
+ if ($privateKey != null && strlen($privateKey) == 33
+ && $enablePrivateKey == true
+ ) {
+ $privateKey = substr($privateKey, 1, 32);
+ }
+
+ // if new user is enabling Private Key, create new key
+ if ($privateKey == null && $enablePrivateKey == true) {
+ $privateKey = $this->getNewPrivateKey();
+ }
+
// Set up the SQL UPDATE statement.
$moddatetime = gmdate('Y-m-d H:i:s', time());
if ($password == '') {
$updates = array(
- 'uModified' => $moddatetime,
- 'name' => $name,
- 'email' => $email,
- 'homepage' => $homepage,
- 'uContent' => $uContent
+ 'uModified' => $moddatetime,
+ 'name' => $name,
+ 'email' => $email,
+ 'homepage' => $homepage,
+ 'uContent' => $uContent,
+ 'privateKey' => $privateKey
);
} else {
$updates = array(
- 'uModified' => $moddatetime,
- 'password' => $this->sanitisePassword($password),
- 'name' => $name,
- 'email' => $email,
- 'homepage' => $homepage,
- 'uContent' => $uContent
+ 'uModified' => $moddatetime,
+ 'password' => $this->sanitisePassword($password),
+ 'name' => $name,
+ 'email' => $email,
+ 'homepage' => $homepage,
+ 'uContent' => $uContent,
+ 'privateKey' => $privateKey
);
}
$sql = 'UPDATE '. $this->getTableName()
@@ -837,6 +934,56 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
}
}
+ /**
+ * Generates a new private key and confirms it isn't being used.
+ * Private key is 32 characters long, consisting of lowercase and
+ * numeric characters.
+ *
+ * @return string the new key value
+ */
+ public function getNewPrivateKey()
+ {
+ do {
+ $newKey = md5(uniqid('SemanticScuttle', true));
+ } while ($this->privateKeyExists($newKey));
+
+ return $newKey;
+ }
+
+ /**
+ * Checks if a private key already exists
+ *
+ * @param string $privateKey key that has been generated
+ *
+ * @return boolean true when the private key exists,
+ * False if not.
+ */
+ public function privateKeyExists($privateKey)
+ {
+ if (!$privateKey) {
+ return false;
+ }
+ $crit = array('privateKey' => $privateKey);
+
+ $sql = 'SELECT COUNT(*) as "0" FROM '
+ . $GLOBALS['tableprefix'] . 'users'
+ . ' WHERE '. $this->db->sql_build_array('SELECT', $crit);
+
+ if (!($dbresult = $this->db->sql_query($sql))) {
+ message_die(
+ GENERAL_ERROR, 'Could not get vars', '',
+ __LINE__, __FILE__, $sql, $this->db
+ );
+ }
+ if ($this->db->sql_fetchfield(0, 0) > 0) {
+ $exists = true;
+ } else {
+ $exists = false;
+ }
+ $this->db->sql_freeresult($dbresult);
+ return $exists;
+ }
+
function isReserved($username) {
if (in_array($username, $GLOBALS['reservedusers'])) {
return true;
--
cgit v1.2.3-54-g00ecf
From 6ed90e647a0a513def828ec66f17df2b724c518e Mon Sep 17 00:00:00 2001
From: Mark Pemberton
Date: Sat, 14 May 2011 21:46:35 -0400
Subject: Fixed sql commands where resources were not freed
---
src/SemanticScuttle/Service/Bookmark.php | 1 +
src/SemanticScuttle/Service/User.php | 9 ++++---
www/ajaxGetNewPrivateKey.php | 42 ++++++++++++++++++++++++++++++++
3 files changed, 48 insertions(+), 4 deletions(-)
create mode 100644 www/ajaxGetNewPrivateKey.php
(limited to 'src/SemanticScuttle')
diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php
index e836cd8..57d0b2e 100644
--- a/src/SemanticScuttle/Service/Bookmark.php
+++ b/src/SemanticScuttle/Service/Bookmark.php
@@ -427,6 +427,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
$existence[$hashes[$row['bHash']]] = $row['count'] > 0;
}
+ $this->db->sql_freeresult($dbresult);
return $existence;
}
diff --git a/src/SemanticScuttle/Service/User.php b/src/SemanticScuttle/Service/User.php
index c3633de..01945ca 100644
--- a/src/SemanticScuttle/Service/User.php
+++ b/src/SemanticScuttle/Service/User.php
@@ -674,11 +674,12 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
return false;
}
- $arrWatch = array();
+ $retval = true;
if ($this->db->sql_numrows($dbresult) == 0)
- return false;
- else
- return true;
+ $retval = false;
+
+ $this->db->sql_freeresult($dbresult);
+ return $retval;
}
function setWatchStatus($subjectUserID) {
diff --git a/www/ajaxGetNewPrivateKey.php b/www/ajaxGetNewPrivateKey.php
new file mode 100644
index 0000000..59545a2
--- /dev/null
+++ b/www/ajaxGetNewPrivateKey.php
@@ -0,0 +1,42 @@
+';
+?>
+
+
+getNewPrivateKey
+
+
+getNewPrivateKey(); ?>
+
+
--
cgit v1.2.3-54-g00ecf
From 10214c43b51e99cc3f8f58a4c4e8893eb2480e62 Mon Sep 17 00:00:00 2001
From: Mark Pemberton
Date: Mon, 16 May 2011 00:35:31 -0400
Subject: Updated 'Generate New Key' button to use ajax if javascript enabled.
---
data/templates/editprofile.tpl.php | 4 +++-
src/SemanticScuttle/Service/Bookmark.php | 11 ++++++-----
www/profile.php | 1 +
3 files changed, 10 insertions(+), 6 deletions(-)
(limited to 'src/SemanticScuttle')
diff --git a/data/templates/editprofile.tpl.php b/data/templates/editprofile.tpl.php
index 76f608a..258e864 100644
--- a/data/templates/editprofile.tpl.php
+++ b/data/templates/editprofile.tpl.php
@@ -33,7 +33,9 @@ $this->includeTemplate($GLOBALS['top_include']);
/>
-
+
+
+
|
diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php
index 57d0b2e..9a075be 100644
--- a/src/SemanticScuttle/Service/Bookmark.php
+++ b/src/SemanticScuttle/Service/Bookmark.php
@@ -728,14 +728,15 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
$privacy = ' AND B.bStatus = 0';
}
+ $tagcount = 0;
// Set up the tags, if need be.
- if (!is_array($tags) && !is_null($tags)) {
+ if (!is_array($tags) && !is_null($tags) && $tags<>"") {
$tags = explode('+', trim($tags));
- }
- $tagcount = count($tags);
- for ($i = 0; $i < $tagcount; $i ++) {
- $tags[$i] = trim($tags[$i]);
+ $tagcount = count($tags);
+ for ($i = 0; $i < $tagcount; $i ++) {
+ $tags[$i] = trim($tags[$i]);
+ }
}
// Set up the SQL query.
diff --git a/www/profile.php b/www/profile.php
index e6894d0..63f4da8 100644
--- a/www/profile.php
+++ b/www/profile.php
@@ -23,6 +23,7 @@ require_once 'www-header.php';
/* Service creation: only useful services are created */
// No specific services
+$tplVars['loadjs'] = true;
/* Managing all possible inputs */
isset($_POST['submittedPK']) ? define('POST_SUBMITTEDPK', $_POST['submittedPK']): define('POST_SUBMITTEDPK', '');
--
cgit v1.2.3-54-g00ecf
From 920f7fc623ecad4f1338ab68326f2817c12c4610 Mon Sep 17 00:00:00 2001
From: Mark Pemberton
Date: Tue, 17 May 2011 00:24:43 -0400
Subject: Updated PrivateKey to include Tag searches
---
data/templates/editprofile.tpl.php | 4 +--
src/SemanticScuttle/Service/Bookmark.php | 37 ++++++++++++++++++----------
src/SemanticScuttle/Service/Bookmark2Tag.php | 2 +-
src/SemanticScuttle/Service/Tag.php | 4 +--
www/bookmarks.php | 17 ++++++++++++-
www/tags.php | 15 ++++++++++-
6 files changed, 58 insertions(+), 21 deletions(-)
(limited to 'src/SemanticScuttle')
diff --git a/data/templates/editprofile.tpl.php b/data/templates/editprofile.tpl.php
index 258e864..25dc3a4 100644
--- a/data/templates/editprofile.tpl.php
+++ b/data/templates/editprofile.tpl.php
@@ -33,9 +33,7 @@ $this->includeTemplate($GLOBALS['top_include']);
/>
-
-
-
+
|
diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php
index 9a075be..232f9d0 100644
--- a/src/SemanticScuttle/Service/Bookmark.php
+++ b/src/SemanticScuttle/Service/Bookmark.php
@@ -821,23 +821,34 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
// Handle the parts of the query that depend on any tags that are present.
$query_4 = '';
- for ($i = 0; $i < $tagcount; $i ++) {
- $query_2 .= ', '. $b2tservice->getTableName() .' AS T'. $i;
+ if ($tagcount > 0) {
+ $query_2 .= ', '. $b2tservice->getTableName() .' AS T0';
$query_4 .= ' AND (';
+
+ $tagArray = array();
+ for ($i = 0; $i < $tagcount; $i ++) {
+ $tmpTag = $this->db->sql_escape($tags[$i]);
+ $allLinkedTags = $tag2tagservice->getAllLinkedTags(
+ $tmpTag, '>', $user
+ );
- $allLinkedTags = $tag2tagservice->getAllLinkedTags(
- $this->db->sql_escape($tags[$i]), '>', $user
- );
+ while (is_array($allLinkedTags) && count($allLinkedTags)>0) {
+ $tmpValue = array_pop($allLinkedTags);
+ if (in_array($tmpValue, $tagArray) == false) {
+ $tagArray[] = $tmpValue;
+ }
+ }
- while (is_array($allLinkedTags) && count($allLinkedTags)>0) {
- $query_4 .= ' T'. $i .'.tag = "'. array_pop($allLinkedTags) .'"';
- $query_4 .= ' OR';
+ if (in_array($tmpTag, $tagArray) == false) {
+ $tagArray[] = $tmpTag;
+ }
}
-
- $query_4 .= ' T'. $i .'.tag = "'. $this->db->sql_escape($tags[$i]) .'"';
-
- $query_4 .= ') AND T'. $i .'.bId = B.bId';
- //die($query_4);
+ // loop through array of possible tags
+ foreach ($tagArray as $k => $v) {
+ $query_4 .= ' T0.tag = "'. $v .'" OR';
+ }
+ $query_4 = substr($query_4,0,-3);
+ $query_4 .= ') AND T0.bId = B.bId';
}
// Search terms
diff --git a/src/SemanticScuttle/Service/Bookmark2Tag.php b/src/SemanticScuttle/Service/Bookmark2Tag.php
index a10cb61..fc59a1c 100644
--- a/src/SemanticScuttle/Service/Bookmark2Tag.php
+++ b/src/SemanticScuttle/Service/Bookmark2Tag.php
@@ -99,7 +99,7 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService
$tags_count = is_array($tags)?count($tags):0;
for ($i = 0; $i < $tags_count; $i++) {
- $tags[$i] = trim(strtolower($tags[$i]));
+ $tags[$i] = trim(utf8_strtolower($tags[$i]));
if ($fromApi) {
include_once 'SemanticScuttle/functions.php';
$tags[$i] = convertTag($tags[$i], 'in');
diff --git a/src/SemanticScuttle/Service/Tag.php b/src/SemanticScuttle/Service/Tag.php
index 25d3888..8325285 100644
--- a/src/SemanticScuttle/Service/Tag.php
+++ b/src/SemanticScuttle/Service/Tag.php
@@ -141,10 +141,10 @@ class SemanticScuttle_Service_Tag extends SemanticScuttle_DbService
//normalize
if(!is_array($tags)) {
- $tags = strtolower(trim($tags));
+ $tags = utf8_strtolower(trim($tags));
} else {
for($i=0; $iisLoggedOn()) {
+ $currentUsername = $currentUser->getUsername();
+ if ($userservice->isPrivateKeyValid($currentUser->getPrivateKey())) {
+ array_push(
+ $tplVars['rsschannels'],
+ array(
+ filter($sitename . $rssTitle. sprintf(T_(': (private) ')) . $currentUsername),
+ createURL('rss', filter($currentUsername, 'url') . '?sort='.getSortOrder().'&privatekey='.$currentUser->getPrivateKey())
+ )
+ );
+ }
+ }
+
$tplVars['page'] = $page;
$tplVars['start'] = $start;
$tplVars['bookmarkCount'] = $start + 1;
diff --git a/www/tags.php b/www/tags.php
index a4e6555..09725e4 100644
--- a/www/tags.php
+++ b/www/tags.php
@@ -67,9 +67,22 @@ if ($usecache) {
$tplVars['pagetitle'] = T_('Tags') .': '. $cat;
$tplVars['loadjs'] = true;
$tplVars['rsschannels'] = array(
-array(filter($sitename .': '. $pagetitle), createURL('rss', 'all/'. filter($cat, 'url')).'?sort='.getSortOrder())
+array(filter($sitename .': Tags: '. $cat), createURL('rss', 'all/'. filter($cat, 'url')).'?sort='.getSortOrder())
);
+if ($userservice->isLoggedOn()) {
+ $currentUsername = $currentUser->getUsername();
+ if ($userservice->isPrivateKeyValid($currentUser->getPrivateKey())) {
+ array_push(
+ $tplVars['rsschannels'],
+ array(
+ filter($sitename .': Tags: '. $cat . sprintf(T_(': (private) ')) . $currentUsername),
+ createURL('rss', filter($currentUsername, 'url') . '?sort='.getSortOrder().'&privatekey='.$currentUser->getPrivateKey())
+ )
+ );
+ }
+}
+
// Pagination
$perpage = getPerPageCount($currentUser);
if (intval(GET_PAGE) > 1) {
--
cgit v1.2.3-54-g00ecf
From 5203848b12ccda0009409e08165bfa2d9d34a837 Mon Sep 17 00:00:00 2001
From: Mark Pemberton
Date: Thu, 19 May 2011 19:40:22 -0400
Subject: revert getBookmarks() back to original
---
src/SemanticScuttle/Service/Bookmark.php | 50 ++++++++++++--------------------
tests/Tag2TagTest.php | 1 +
2 files changed, 20 insertions(+), 31 deletions(-)
(limited to 'src/SemanticScuttle')
diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php
index 232f9d0..17ab7ba 100644
--- a/src/SemanticScuttle/Service/Bookmark.php
+++ b/src/SemanticScuttle/Service/Bookmark.php
@@ -718,7 +718,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
// All public bookmarks, user's own bookmarks
// and any shared with user
$privacy = ' AND ((B.bStatus = 0) OR (B.uId = '. $sId .')';
- $watchnames = $userservice->getWatchNames($sId);
+ $watchnames = $userservice->getWatchNames($sId, true);
foreach ($watchnames as $watchuser) {
$privacy .= ' OR (U.username = "'. $watchuser .'" AND B.bStatus = 1)';
}
@@ -728,15 +728,14 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
$privacy = ' AND B.bStatus = 0';
}
- $tagcount = 0;
// Set up the tags, if need be.
- if (!is_array($tags) && !is_null($tags) && $tags<>"") {
+ if (!is_array($tags) && !is_null($tags)) {
$tags = explode('+', trim($tags));
+ }
- $tagcount = count($tags);
- for ($i = 0; $i < $tagcount; $i ++) {
- $tags[$i] = trim($tags[$i]);
- }
+ $tagcount = count($tags);
+ for ($i = 0; $i < $tagcount; $i ++) {
+ $tags[$i] = trim($tags[$i]);
}
// Set up the SQL query.
@@ -821,34 +820,23 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
// Handle the parts of the query that depend on any tags that are present.
$query_4 = '';
- if ($tagcount > 0) {
- $query_2 .= ', '. $b2tservice->getTableName() .' AS T0';
+ for ($i = 0; $i < $tagcount; $i ++) {
+ $query_2 .= ', '. $b2tservice->getTableName() .' AS T'. $i;
$query_4 .= ' AND (';
-
- $tagArray = array();
- for ($i = 0; $i < $tagcount; $i ++) {
- $tmpTag = $this->db->sql_escape($tags[$i]);
- $allLinkedTags = $tag2tagservice->getAllLinkedTags(
- $tmpTag, '>', $user
- );
- while (is_array($allLinkedTags) && count($allLinkedTags)>0) {
- $tmpValue = array_pop($allLinkedTags);
- if (in_array($tmpValue, $tagArray) == false) {
- $tagArray[] = $tmpValue;
- }
- }
+ $allLinkedTags = $tag2tagservice->getAllLinkedTags(
+ $this->db->sql_escape($tags[$i]), '>', $user
+ );
- if (in_array($tmpTag, $tagArray) == false) {
- $tagArray[] = $tmpTag;
- }
- }
- // loop through array of possible tags
- foreach ($tagArray as $k => $v) {
- $query_4 .= ' T0.tag = "'. $v .'" OR';
+ while (is_array($allLinkedTags) && count($allLinkedTags)>0) {
+ $query_4 .= ' T'. $i .'.tag = "'. array_pop($allLinkedTags) .'"';
+ $query_4 .= ' OR';
}
- $query_4 = substr($query_4,0,-3);
- $query_4 .= ') AND T0.bId = B.bId';
+
+ $query_4 .= ' T'. $i .'.tag = "'. $this->db->sql_escape($tags[$i]) .'"';
+
+ $query_4 .= ') AND T'. $i .'.bId = B.bId';
+ //die($query_4);
}
// Search terms
diff --git a/tests/Tag2TagTest.php b/tests/Tag2TagTest.php
index 0b73864..58556f1 100644
--- a/tests/Tag2TagTest.php
+++ b/tests/Tag2TagTest.php
@@ -332,6 +332,7 @@ class Tag2TagTest extends TestBase
$this->assertSame('B3', $results['bookmarks'][0]['bTitle']);
$results = $bs->getBookmarks(0, NULL, 1, 'aa+ee');
+
$this->assertSame(1, intval($results['total']));
$this->assertSame('B2', $results['bookmarks'][0]['bTitle']);
--
cgit v1.2.3-54-g00ecf
From 342d1c3205c2f2ae9d918f66e28e8ffa153c2854 Mon Sep 17 00:00:00 2001
From: Mark Pemberton
Date: Sat, 21 May 2011 22:06:44 -0400
Subject: Altered tests to be more timezone friendly
---
src/SemanticScuttle/Service/Bookmark.php | 2 +-
tests/Api/PostsAddTest.php | 4 ++--
tests/Bookmark2TagTest.php | 12 ++++++------
3 files changed, 9 insertions(+), 9 deletions(-)
(limited to 'src/SemanticScuttle')
diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php
index 17ab7ba..f69b4d1 100644
--- a/src/SemanticScuttle/Service/Bookmark.php
+++ b/src/SemanticScuttle/Service/Bookmark.php
@@ -486,7 +486,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
} else {
$time = strtotime($date);
}
- $datetime = gmdate('Y-m-d H:i:s', $time);
+ $datetime = date('Y-m-d H:i:s', $time);
if ($short === '') {
$short = null;
diff --git a/tests/Api/PostsAddTest.php b/tests/Api/PostsAddTest.php
index e6d0531..2613a87 100644
--- a/tests/Api/PostsAddTest.php
+++ b/tests/Api/PostsAddTest.php
@@ -111,7 +111,7 @@ TXT;
$this->assertEquals($bmDescription, stripslashes($bm['bDescription']));
$this->assertEquals($bmTags, $bm['tags']);
$this->assertEquals(
- gmdate('Y-m-d H:i:s', strtotime($bmDatetime)),
+ date('Y-m-d H:i:s', strtotime($bmDatetime)),
$bm['bDatetime']
);
}
@@ -173,7 +173,7 @@ TXT;
$this->assertEquals($bmDescription, stripslashes($bm['bDescription']));
$this->assertEquals($bmTags, $bm['tags']);
$this->assertEquals(
- gmdate('Y-m-d H:i:s', strtotime($bmDatetime)),
+ date('Y-m-d H:i:s', strtotime($bmDatetime)),
$bm['bDatetime']
);
}
diff --git a/tests/Bookmark2TagTest.php b/tests/Bookmark2TagTest.php
index 66a6e1f..0236a5f 100644
--- a/tests/Bookmark2TagTest.php
+++ b/tests/Bookmark2TagTest.php
@@ -282,16 +282,16 @@ class Bookmark2TagTest extends TestBase
public function testGetPopularTagsDays()
{
$user = $this->addUser();
- $this->addTagBookmark($user, array('one', 'two'), 'today');
- $this->addTagBookmark($user, array('one', 'thr'), 'today');
- $this->addTagBookmark($user, array('one', 'two'), '-1 day 1 hour');
- $this->addTagBookmark($user, array('one', 'thr'), '-3 days 1 hour');
+ $this->addTagBookmark($user, array('one', 'two'), 'now');
+ $this->addTagBookmark($user, array('one', 'thr'), 'now');
+ $this->addTagBookmark($user, array('one', 'two'), '-1 day -1 hour');
+ $this->addTagBookmark($user, array('one', 'thr'), '-3 days -1 hour');
$arTags = $this->b2ts->getPopularTags(null, 10, null, 1);
$this->assertInternalType('array', $arTags);
$this->assertEquals(3, count($arTags));
- $this->assertContains(array('tag' => 'one', 'bCount' => '3'), $arTags);
- $this->assertContains(array('tag' => 'two', 'bCount' => '2'), $arTags);
+ $this->assertContains(array('tag' => 'one', 'bCount' => '2'), $arTags);
+ $this->assertContains(array('tag' => 'two', 'bCount' => '1'), $arTags);
$this->assertContains(array('tag' => 'thr', 'bCount' => '1'), $arTags);
$arTags = $this->b2ts->getPopularTags(null, 10, null, 2);
--
cgit v1.2.3-54-g00ecf
From 84e603aa91a303a1419962ff3ff6086710a7b1a9 Mon Sep 17 00:00:00 2001
From: Mark Pemberton
Date: Sat, 4 Jun 2011 00:29:04 -0400
Subject: Reverted changes of date() to gdate(), added tests to confirm
existence of private RSS feed, and finalized changes to the user session
usage with rss.php
---
src/SemanticScuttle/Service/Bookmark.php | 2 +-
src/SemanticScuttle/Service/Bookmark2Tag.php | 2 +-
src/SemanticScuttle/Service/User.php | 2 --
tests/Api/PostsAddTest.php | 4 ++--
tests/TestBaseApi.php | 21 ++++++++++++-------
tests/www/bookmarksTest.php | 27 ++++++++++++++++++++++++
www/ajaxGetNewPrivateKey.php | 31 +++++++++++-----------------
www/index.php | 2 +-
www/jsScuttle.php | 8 +++++++
www/rss.php | 14 ++-----------
10 files changed, 68 insertions(+), 45 deletions(-)
(limited to 'src/SemanticScuttle')
diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php
index f69b4d1..17ab7ba 100644
--- a/src/SemanticScuttle/Service/Bookmark.php
+++ b/src/SemanticScuttle/Service/Bookmark.php
@@ -486,7 +486,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
} else {
$time = strtotime($date);
}
- $datetime = date('Y-m-d H:i:s', $time);
+ $datetime = gmdate('Y-m-d H:i:s', $time);
if ($short === '') {
$short = null;
diff --git a/src/SemanticScuttle/Service/Bookmark2Tag.php b/src/SemanticScuttle/Service/Bookmark2Tag.php
index fc59a1c..04ee43d 100644
--- a/src/SemanticScuttle/Service/Bookmark2Tag.php
+++ b/src/SemanticScuttle/Service/Bookmark2Tag.php
@@ -584,7 +584,7 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService
if (is_int($days)) {
$query .= ' AND B.bDatetime > "'
- . date('Y-m-d H:i:s', time() - (86400 * $days))
+ . gmdate('Y-m-d H:i:s', time() - (86400 * $days))
. '"';
}
diff --git a/src/SemanticScuttle/Service/User.php b/src/SemanticScuttle/Service/User.php
index 18d5a29..a4870b7 100644
--- a/src/SemanticScuttle/Service/User.php
+++ b/src/SemanticScuttle/Service/User.php
@@ -571,8 +571,6 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
$this->db->sql_freeresult($dbresult);
if ($row) {
- $id = $_SESSION[$this->getSessionKey()]
- = $row[$this->getFieldName('primary')];
return true;
} else {
return false;
diff --git a/tests/Api/PostsAddTest.php b/tests/Api/PostsAddTest.php
index 2613a87..e6d0531 100644
--- a/tests/Api/PostsAddTest.php
+++ b/tests/Api/PostsAddTest.php
@@ -111,7 +111,7 @@ TXT;
$this->assertEquals($bmDescription, stripslashes($bm['bDescription']));
$this->assertEquals($bmTags, $bm['tags']);
$this->assertEquals(
- date('Y-m-d H:i:s', strtotime($bmDatetime)),
+ gmdate('Y-m-d H:i:s', strtotime($bmDatetime)),
$bm['bDatetime']
);
}
@@ -173,7 +173,7 @@ TXT;
$this->assertEquals($bmDescription, stripslashes($bm['bDescription']));
$this->assertEquals($bmTags, $bm['tags']);
$this->assertEquals(
- date('Y-m-d H:i:s', strtotime($bmDatetime)),
+ gmdate('Y-m-d H:i:s', strtotime($bmDatetime)),
$bm['bDatetime']
);
}
diff --git a/tests/TestBaseApi.php b/tests/TestBaseApi.php
index 20574f3..d8917aa 100644
--- a/tests/TestBaseApi.php
+++ b/tests/TestBaseApi.php
@@ -164,15 +164,16 @@ class TestBaseApi extends TestBase
*
* Useful for testing HTML pages or ajax URLs.
*
- * @param string $urlSuffix Suffix for the URL
- * @param mixed $auth If user authentication is needed (true/false)
- * or array with username and password
+ * @param string $urlSuffix Suffix for the URL
+ * @param mixed $auth If user authentication is needed (true/false)
+ * or array with username and password
+ * @param boolean $privateKey True if to add user with private key
*
* @return array(HTTP_Request2, integer) HTTP request object and user id
*
* @uses getRequest()
*/
- protected function getLoggedInRequest($urlSuffix = null, $auth = true)
+ protected function getLoggedInRequest($urlSuffix = null, $auth = true, $privateKey = false)
{
if (is_array($auth)) {
list($username, $password) = $auth;
@@ -180,7 +181,13 @@ class TestBaseApi extends TestBase
$username = 'testuser';
$password = 'testpassword';
}
- $uid = $this->addUser($username, $password);
+ //include privatekey if requested
+ if ($privateKey) {
+ $pKey = $this->us->getNewPrivateKey();
+ } else {
+ $pKey = null;
+ }
+ $uid = $this->addUser($username, $password, $pKey);
$req = new HTTP_Request2(
$GLOBALS['unittestUrl'] . '/login.php?unittestMode=1',
@@ -234,7 +241,7 @@ class TestBaseApi extends TestBase
*/
protected function setUnittestConfig($arConfig)
{
- $str = '<' . "?php\r\n";
+ $str = '<' . "?php\n";
foreach ($arConfig as $name => $value) {
$str .= '$' . $name . ' = '
. var_export($value, true) . ";\n";
@@ -253,4 +260,4 @@ class TestBaseApi extends TestBase
);
}
}
-?>
\ No newline at end of file
+?>
diff --git a/tests/www/bookmarksTest.php b/tests/www/bookmarksTest.php
index df360cc..eaf78bf 100755
--- a/tests/www/bookmarksTest.php
+++ b/tests/www/bookmarksTest.php
@@ -76,5 +76,32 @@ class www_bookmarksTest extends TestBaseApi
$this->assertEquals(1, (string)$elements[0]['value']);
}//end testDefaultPrivacyBookmarksAdd
+
+ /**
+ * Test that the private RSS link exists when a user
+ * has a private key and is enabled
+ */
+ public function testVerifyPrivateRSSLinkExists()
+ {
+ list($req, $uId) = $this->getLoggedInRequest('?unittestMode=1', true, true);
+
+ $user = $this->us->getUser($uId);
+ $reqUrl = $GLOBALS['unittestUrl'] . 'bookmarks.php/'
+ . $user['username'];
+ $req->setUrl($reqUrl);
+ $req->setMethod(HTTP_Request2::METHOD_GET);
+ $response = $req->send();
+ $response_body = $response->getBody();
+ $this->assertNotEquals('', $response_body, 'Response is empty');
+
+ $x = simplexml_load_string($response_body);
+ $ns = $x->getDocNamespaces();
+ $x->registerXPathNamespace('ns', reset($ns));
+
+ $elements = $x->xpath('//ns:link');
+ $this->assertEquals(5, count($elements), 'Number of Links in Head not correct');
+ $this->assertContains('privatekey=', (string)$elements[4]['href']);
+ }//end testVerifyPrivateRSSLinkExists
+
}//end class www_bookmarksTest
?>
diff --git a/www/ajaxGetNewPrivateKey.php b/www/ajaxGetNewPrivateKey.php
index 59545a2..eacebd8 100644
--- a/www/ajaxGetNewPrivateKey.php
+++ b/www/ajaxGetNewPrivateKey.php
@@ -1,23 +1,16 @@
+ * @author Mark Pemberton
+ * @license AGPL http://www.gnu.org/licenses/agpl.html
+ * @link http://sourceforge.net/projects/semanticscuttle
+ */
header("Last-Modified: ". gmdate("D, d M Y H:i:s") ." GMT");
header("Cache-Control: no-cache, must-revalidate");
diff --git a/www/index.php b/www/index.php
index 931d64d..fab235f 100644
--- a/www/index.php
+++ b/www/index.php
@@ -51,7 +51,7 @@ if ($userservice->isLoggedOn()) {
array_push(
$tplVars['rsschannels'],
array(
- filter($sitename . sprintf(T_(': (private) ')) . $currentUsername),
+ filter($sitename . sprintf(T_(': Recent bookmarks (private)')) . $currentUsername),
createURL('rss', filter($currentUsername, 'url') . '?sort='.getSortOrder().'&privatekey='.$currentUser->getPrivateKey())
)
);
diff --git a/www/jsScuttle.php b/www/jsScuttle.php
index 76b49dc..3ca41ec 100644
--- a/www/jsScuttle.php
+++ b/www/jsScuttle.php
@@ -89,6 +89,14 @@ function useAddress(ele) {
}
}
+/**
+ * Makes an ajax call to PHP script to generate an new Private Key
+ *
+ * @param input Calling object
+ * @param response Response object that returned value is placed
+ *
+ * @return boolean Returns false to halt execution after call
+ */
function getNewPrivateKey(input, response){
var pk = document.getElementById('pPrivateKey');
if (response != null) {
diff --git a/www/rss.php b/www/rss.php
index 8c81e0e..2927534 100644
--- a/www/rss.php
+++ b/www/rss.php
@@ -71,7 +71,6 @@ if (isset($_GET['privatekey'])) {
$watchlist = null;
$pagetitle = '';
-$isTempLogin = false;
if ($user && $user != 'all') {
if ($user == 'watchlist') {
$user = $cat;
@@ -86,9 +85,7 @@ if ($user && $user != 'all') {
/* if user is not logged in and has valid privatekey */
if (!$userservice->isLoggedOn()) {
if ($privatekey != null) {
- if ($userservice->loginPrivateKey($privatekey)) {
- $isTempLogin = true;
- } else {
+ if (!$userservice->loginPrivateKey($privatekey)) {
$tplVars['error'] = sprintf(T_('Failed to Autenticate User with username %s using private key'), $user);
header('Content-type: text/html; charset=utf-8');
$templateservice->loadTemplate('error.404.tpl', $tplVars);
@@ -109,9 +106,7 @@ if ($user && $user != 'all') {
$pagetitle .= ": ". $user;
} else {
if ($privatekey != null) {
- if ($userservice->loginPrivateKey($privatekey)) {
- $isTempLogin = true;
- } else {
+ if (!$userservice->loginPrivateKey($privatekey)) {
$tplVars['error'] = sprintf(T_('Failed to Autenticate User with username %s using private key'), $user);
header('Content-type: text/html; charset=utf-8');
$templateservice->loadTemplate('error.404.tpl', $tplVars);
@@ -168,11 +163,6 @@ $tplVars['feedlastupdate'] = date('r', strtotime($latestdate));
$templateservice->loadTemplate('rss.tpl', $tplVars);
-/* If temporary login, please log out */
-if ($isTempLogin) {
- $userservice->logout();
-}
-
if ($usecache) {
// Cache output if existing copy has expired
$cacheservice->End($hash);
--
cgit v1.2.3-54-g00ecf
From 74bab13f05ee7552c13e0dc8f4523cd7071a0085 Mon Sep 17 00:00:00 2001
From: Mark Pemberton
Date: Tue, 14 Jun 2011 22:39:47 -0400
Subject: Fixed auth issue with private RSS feed
---
src/SemanticScuttle/Service/User.php | 1 +
1 file changed, 1 insertion(+)
(limited to 'src/SemanticScuttle')
diff --git a/src/SemanticScuttle/Service/User.php b/src/SemanticScuttle/Service/User.php
index a4870b7..e6527ea 100644
--- a/src/SemanticScuttle/Service/User.php
+++ b/src/SemanticScuttle/Service/User.php
@@ -571,6 +571,7 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
$this->db->sql_freeresult($dbresult);
if ($row) {
+ $this->setCurrentUserId($row[$this->getFieldName('primary')], true);
return true;
} else {
return false;
--
cgit v1.2.3-54-g00ecf
From f9dbdc6645ed3631d9ba77a29212934073bd76b4 Mon Sep 17 00:00:00 2001
From: Mark Pemberton
Date: Wed, 15 Jun 2011 08:47:50 -0400
Subject: Fixed issue with storing RSS login in session
---
src/SemanticScuttle/Service/User.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'src/SemanticScuttle')
diff --git a/src/SemanticScuttle/Service/User.php b/src/SemanticScuttle/Service/User.php
index e6527ea..b5b053f 100644
--- a/src/SemanticScuttle/Service/User.php
+++ b/src/SemanticScuttle/Service/User.php
@@ -571,7 +571,7 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
$this->db->sql_freeresult($dbresult);
if ($row) {
- $this->setCurrentUserId($row[$this->getFieldName('primary')], true);
+ $this->setCurrentUserId($row[$this->getFieldName('primary')], false);
return true;
} else {
return false;
--
cgit v1.2.3-54-g00ecf
From 6ec3b102aa896df8ddcf6323e0635dc42ac25f98 Mon Sep 17 00:00:00 2001
From: Christian Weiske
Date: Mon, 27 Jun 2011 19:39:38 +0200
Subject: make the private tests really test something
---
src/SemanticScuttle/Model/Bookmark.php | 17 ++++++++
tests/TestBase.php | 8 ++--
tests/TestBaseApi.php | 15 ++-----
tests/www/rssTest.php | 73 +++++++++-------------------------
4 files changed, 42 insertions(+), 71 deletions(-)
(limited to 'src/SemanticScuttle')
diff --git a/src/SemanticScuttle/Model/Bookmark.php b/src/SemanticScuttle/Model/Bookmark.php
index 8bda0b3..1330642 100644
--- a/src/SemanticScuttle/Model/Bookmark.php
+++ b/src/SemanticScuttle/Model/Bookmark.php
@@ -23,6 +23,23 @@
*/
class SemanticScuttle_Model_Bookmark
{
+ /**
+ * Status "public" / visible for all
+ */
+ const SPUBLIC = 0;
+
+ /**
+ * Status "shared" / visible for people on your watchlist
+ */
+ const SWATCHLIST = 1;
+
+ /**
+ * Status "private" / visible for yourself only
+ */
+ const SPRIVATE = 2;
+
+
+
/**
* Checks if the given URL is valid and may be used with this
* SemanticScuttle installation.
diff --git a/tests/TestBase.php b/tests/TestBase.php
index 5ea656c..2180d2d 100644
--- a/tests/TestBase.php
+++ b/tests/TestBase.php
@@ -76,8 +76,8 @@ class TestBase extends PHPUnit_Framework_TestCase
/**
* Creates a new user in the database.
*
- * @param string $username Username
- * @param string $password Password
+ * @param string $username Username, may be null
+ * @param string $password Password, may be null
* @param mixed $privateKey String private key or boolean true to generate one
*
* @return integer ID of user
@@ -95,8 +95,8 @@ class TestBase extends PHPUnit_Framework_TestCase
/**
* Creates a new user in the database and returns id, username and password.
*
- * @param string $username Username
- * @param string $password Password
+ * @param string $username Username, may be null
+ * @param string $password Password, may be null
* @param mixed $privateKey String private key or boolean true to generate one
*
* @return array ID of user, Name of user, password of user, privatekey
diff --git a/tests/TestBaseApi.php b/tests/TestBaseApi.php
index f860d10..1052ae7 100644
--- a/tests/TestBaseApi.php
+++ b/tests/TestBaseApi.php
@@ -187,8 +187,7 @@ class TestBaseApi extends TestBase
* @uses getRequest()
*/
protected function getLoggedInRequest(
- $urlSuffix = null, $auth = true, $privateKey = false,
- $setCookie = true
+ $urlSuffix = null, $auth = true, $privateKey = null
) {
if (is_array($auth)) {
list($username, $password) = $auth;
@@ -196,13 +195,7 @@ class TestBaseApi extends TestBase
$username = 'testuser';
$password = 'testpassword';
}
- //include privatekey if requested
- if ($privateKey) {
- $pKey = $this->us->getNewPrivateKey();
- } else {
- $pKey = null;
- }
- $uid = $this->addUser($username, $password, $pKey);
+ $uid = $this->addUser($username, $password, $privateKey);
$req = new HTTP_Request2(
$GLOBALS['unittestUrl'] . '/login.php?unittestMode=1',
@@ -218,9 +211,7 @@ class TestBaseApi extends TestBase
$this->assertEquals(302, $res->getStatus(), 'Login failure');
$req = $this->getRequest($urlSuffix);
- if ($setCookie) {
- $req->setCookieJar($cookies);
- }
+ $req->setCookieJar($cookies);
return array($req, $uid);
}
diff --git a/tests/www/rssTest.php b/tests/www/rssTest.php
index 9d4e41b..fc49264 100644
--- a/tests/www/rssTest.php
+++ b/tests/www/rssTest.php
@@ -7,44 +7,23 @@ class www_rssTest extends TestBaseApi
protected $urlPart = 'rss.php';
/**
- * Test a user who does not have RSS private key enabled
- * and with a private bookmark.
+ * A private bookmark should not show up in an rss feed if the
+ * user is not logged in nor passes the private key
*/
- public function testNoRSSPrivateKeyEnabled()
+ public function testPrivateNotLoggedIn()
{
- $this->setUnittestConfig(
- array('defaults' => array('privacy' => 2))
+ list($uId, $username) = $this->addUserData();
+ $this->addBookmark(
+ $uId, null, SemanticScuttle_Model_Bookmark::SPRIVATE
);
- /* create user without RSS private Key */
- list($req, $uId) = $this->getLoggedInRequest(null, true, false, false);
-
- /* create private bookmark */
- $this->bs->addBookmark(
- 'http://test', 'test', 'desc', 'note',
- 2,//private
- array(), null, null, false, false, $uId
- );
- /* create public bookmark */
- $this->bs->addBookmark(
- 'http://example.org', 'title', 'desc', 'priv',
- 0,//public
- array(), null, null, false, false, $uId
- );
-
- /* get user details */
- $user = $this->us->getUser($uId);
-
- $req->setMethod(HTTP_Request2::METHOD_POST);
- $req->setUrl($this->getTestUrl('/' . $user['username'] . '?sort=date_desc'));
- $response = $req->send();
- $response_body = $response->getBody();
+ $req = $this->getRequest('/' . $username);
+ $response_body = $req->send()->getBody();
$rss = simplexml_load_string($response_body);
$items = $rss->channel->item;
- $this->assertEquals(1, count($items), 'Incorrect Number of RSS Items');
- $this->assertEquals('title', (string)$items[0]->title);
+ $this->assertEquals(0, count($items), 'I see a private bookmark');
}//end testNoRSSPrivateKeyEnabled
@@ -54,38 +33,22 @@ class www_rssTest extends TestBaseApi
*/
public function testRSSPrivateKeyEnabled()
{
- $this->setUnittestConfig(
- array('defaults' => array('privacy' => 2))
+ list($uId, $username, $password, $privateKey) = $this->addUserData(
+ null, null, true
);
-
- /* create user with RSS private Key */
- list($req, $uId) = $this->getLoggedInRequest(null, true, false, true);
-
- /* create private bookmark */
- $this->bs->addBookmark(
- 'http://test', 'test', 'desc', 'note',
- 2,//private
- array(), null, null, false, false, $uId
+ $this->addBookmark(
+ $uId, null, SemanticScuttle_Model_Bookmark::SPRIVATE,
+ null, 'private bookmark'
);
- /* create public bookmark */
- $this->bs->addBookmark(
- 'http://example.org', 'title', 'desc', 'priv',
- 0,//public
- array(), null, null, false, false, $uId
- );
-
- /* get user details */
- $user = $this->us->getUser($uId);
- $req->setMethod(HTTP_Request2::METHOD_POST);
- $req->setUrl($this->getTestUrl('/' . $user['username'] . '?sort=date_desc&privatekey=' . $user['privateKey']));
- $response = $req->send();
- $response_body = $response->getBody();
+ $req = $this->getRequest('/' . $username . '?privatekey=' . $privateKey);
+ $response_body = $req->send()->getBody();
$rss = simplexml_load_string($response_body);
$items = $rss->channel->item;
- $this->assertEquals(2, count($items), 'Incorrect Number of RSS Items');
+ $this->assertEquals(1, count($items), 'I miss the private bookmark');
+ $this->assertEquals('private bookmark', (string)$items[0]->title);
}//end testRSSPrivateKeyEnabled
--
cgit v1.2.3-54-g00ecf
From 3d11286cbcc3cb35efe11f6e4a4ef5ac81620bda Mon Sep 17 00:00:00 2001
From: Christian Weiske
Date: Mon, 27 Jun 2011 22:31:24 +0200
Subject: privatekey -> privateKey everywhere
---
src/SemanticScuttle/Service/User.php | 20 ++++++++++----------
tests/TestBase.php | 2 +-
tests/UserTest.php | 24 ++++++++++++------------
tests/www/bookmarksTest.php | 4 ++--
tests/www/indexTest.php | 4 ++--
tests/www/rssTest.php | 6 +++---
www/bookmarks.php | 2 +-
www/index.php | 2 +-
www/rss.php | 16 ++++++++--------
www/tags.php | 2 +-
10 files changed, 41 insertions(+), 41 deletions(-)
(limited to 'src/SemanticScuttle')
diff --git a/src/SemanticScuttle/Service/User.php b/src/SemanticScuttle/Service/User.php
index b5b053f..7550ed2 100644
--- a/src/SemanticScuttle/Service/User.php
+++ b/src/SemanticScuttle/Service/User.php
@@ -51,7 +51,7 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
'primary' => 'uId',
'username' => 'username',
'password' => 'password',
- 'privatekey' => 'privatekey'
+ 'privateKey' => 'privateKey'
);
protected $profileurl;
@@ -219,13 +219,13 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
/**
* Returns user row from database.
*
- * @param string $privatekey Private Key
+ * @param string $privateKey Private Key
*
* @return array User array from database, false if no user was found
*/
- public function getUserByPrivateKey($privatekey)
+ public function getUserByPrivateKey($privateKey)
{
- return $this->_getuser($this->getFieldName('privatekey'), $privatekey);
+ return $this->_getuser($this->getFieldName('privateKey'), $privateKey);
}
function getObjectUserByUsername($username) {
@@ -539,24 +539,24 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
}
/**
- * Try to authenticate via the privatekey
+ * Try to authenticate via the privateKey
*
- * @param string $privatekey Private Key
+ * @param string $privateKey Private Key
*
* @return boolean true if the user could be authenticated,
* false if not.
*/
- public function loginPrivateKey($privatekey)
+ public function loginPrivateKey($privateKey)
{
/* Check if private key valid and enabled */
- if (!$this->isPrivateKeyValid($privatekey)) {
+ if (!$this->isPrivateKeyValid($privateKey)) {
return false;
}
$query = 'SELECT '. $this->getFieldName('primary') .' FROM '
. $this->getTableName() .' WHERE '
- . $this->getFieldName('privatekey') .' = "'
- . $this->db->sql_escape($privatekey) .'"';
+ . $this->getFieldName('privateKey') .' = "'
+ . $this->db->sql_escape($privateKey) .'"';
if (!($dbresult = $this->db->sql_query($query))) {
message_die(
diff --git a/tests/TestBase.php b/tests/TestBase.php
index 2180d2d..2914749 100644
--- a/tests/TestBase.php
+++ b/tests/TestBase.php
@@ -99,7 +99,7 @@ class TestBase extends PHPUnit_Framework_TestCase
* @param string $password Password, may be null
* @param mixed $privateKey String private key or boolean true to generate one
*
- * @return array ID of user, Name of user, password of user, privatekey
+ * @return array ID of user, Name of user, password of user, privateKey
*/
protected function addUserData(
$username = null, $password = null, $privateKey = null
diff --git a/tests/UserTest.php b/tests/UserTest.php
index 230167d..6cd6786 100644
--- a/tests/UserTest.php
+++ b/tests/UserTest.php
@@ -40,7 +40,7 @@ class UserTest extends TestBase
public function testAddUserPrivateKey()
{
$name = substr(md5(uniqid()), 0, 6);
- $pkey = 'my-privatekey';
+ $pkey = 'my-privateKey';
$id = $this->us->addUser(
$name, uniqid(), 'foo@example.org', $pkey
);
@@ -413,17 +413,17 @@ class UserTest extends TestBase
$randKey2 = '-'.$this->us->getNewPrivateKey();
$this->assertFalse(
$this->us->isPrivateKeyValid($randKey2),
- 'disabled privatekey should return false'
+ 'disabled privateKey should return false'
);
}
public function testLoginPrivateKeyInvalid()
{
- /* normal user with enabled privatekey */
+ /* normal user with enabled privateKey */
$randKey = $this->us->getNewPrivateKey();
$uid1 = $this->addUser('testusername', 'passw0rd', $randKey);
- /* user that has disabled privatekey */
+ /* user that has disabled privateKey */
$randKey2 = '-'.$this->us->getNewPrivateKey();
$uid2 = $this->addUser('seconduser', 'passw0RD', $randKey2);
@@ -436,10 +436,10 @@ class UserTest extends TestBase
public function testLoginPrivateKeyValidEnabledKey()
{
- /* normal user with enabled privatekey */
+ /* normal user with enabled privateKey */
$randKey = $this->us->getNewPrivateKey();
$uid1 = $this->addUser('testusername', 'passw0rd', $randKey);
- /* user that has disabled privatekey */
+ /* user that has disabled privateKey */
$randKey2 = '-'.$this->us->getNewPrivateKey();
$uid2 = $this->addUser('seconduser', 'passw0RD', $randKey2);
@@ -453,10 +453,10 @@ class UserTest extends TestBase
public function testLoginPrivateKeyInvalidEnabledKey()
{
- /* normal user with enabled privatekey */
+ /* normal user with enabled privateKey */
$randKey = $this->us->getNewPrivateKey();
$uid1 = $this->addUser('testusername', 'passw0rd', $randKey);
- /* user that has disabled privatekey */
+ /* user that has disabled privateKey */
$randKey2 = '-'.$this->us->getNewPrivateKey();
$uid2 = $this->addUser('seconduser', 'passw0RD', $randKey2);
@@ -470,10 +470,10 @@ class UserTest extends TestBase
public function testLoginPrivateKeyValidDisabledKey()
{
- /* normal user with enabled privatekey */
+ /* normal user with enabled privateKey */
$randKey = $this->us->getNewPrivateKey();
$uid1 = $this->addUser('testusername', 'passw0rd', $randKey);
- /* user that has disabled privatekey */
+ /* user that has disabled privateKey */
$randKey2 = '-'.$this->us->getNewPrivateKey();
$uid2 = $this->addUser('seconduser', 'passw0RD', $randKey2);
@@ -491,10 +491,10 @@ class UserTest extends TestBase
public function testLoginPrivateKeyInvalidDisabled()
{
- /* normal user with enabled privatekey */
+ /* normal user with enabled privateKey */
$randKey = $this->us->getNewPrivateKey();
$uid1 = $this->addUser('testusername', 'passw0rd', $randKey);
- /* user that has disabled privatekey */
+ /* user that has disabled privateKey */
$randKey2 = '-'.$this->us->getNewPrivateKey();
$uid2 = $this->addUser('seconduser', 'passw0RD', $randKey2);
diff --git a/tests/www/bookmarksTest.php b/tests/www/bookmarksTest.php
index 1e1f4eb..ae82118 100755
--- a/tests/www/bookmarksTest.php
+++ b/tests/www/bookmarksTest.php
@@ -92,7 +92,7 @@ class www_bookmarksTest extends TestBaseApi
$this->assertEquals(
2, count($elements), 'Number of Links in Head not correct'
);
- $this->assertContains('privatekey=', (string)$elements[1]['href']);
+ $this->assertContains('privateKey=', (string)$elements[1]['href']);
}//end testVerifyPrivateRSSLinkExists
@@ -121,7 +121,7 @@ class www_bookmarksTest extends TestBaseApi
$this->assertEquals(
1, count($elements), 'Number of Links in Head not correct'
);
- $this->assertNotContains('privatekey=', (string)$elements[0]['href']);
+ $this->assertNotContains('privateKey=', (string)$elements[0]['href']);
}//end testVerifyPrivateRSSLinkDoesNotExist
}//end class www_bookmarksTest
diff --git a/tests/www/indexTest.php b/tests/www/indexTest.php
index 18cb75a..503fd1f 100644
--- a/tests/www/indexTest.php
+++ b/tests/www/indexTest.php
@@ -26,7 +26,7 @@ class www_indexTest extends TestBaseApi
$elements = $x->xpath('//ns:link[@rel="alternate" and @type="application/rss+xml"]');
$this->assertEquals(2, count($elements), 'Number of Links in Head not correct');
- $this->assertContains('privatekey=', (string)$elements[1]['href']);
+ $this->assertContains('privateKey=', (string)$elements[1]['href']);
}//end testVerifyPrivateRSSLinkExists
@@ -50,7 +50,7 @@ class www_indexTest extends TestBaseApi
$elements = $x->xpath('//ns:link[@rel="alternate" and @type="application/rss+xml"]');
$this->assertEquals(1, count($elements), 'Number of Links in Head not correct');
- $this->assertNotContains('privatekey=', (string)$elements[0]['href']);
+ $this->assertNotContains('privateKey=', (string)$elements[0]['href']);
}//end testVerifyPrivateRSSLinkDoesNotExist
diff --git a/tests/www/rssTest.php b/tests/www/rssTest.php
index 75e4363..71d0198 100644
--- a/tests/www/rssTest.php
+++ b/tests/www/rssTest.php
@@ -78,7 +78,7 @@ class www_rssTest extends TestBaseApi
null, 'private bookmark'
);
- $req = $this->getRequest('?privatekey=' . $privateKey);
+ $req = $this->getRequest('?privateKey=' . $privateKey);
$response_body = $req->send()->getBody();
$rss = simplexml_load_string($response_body);
@@ -103,7 +103,7 @@ class www_rssTest extends TestBaseApi
null, 'private bookmark'
);
- $req = $this->getRequest('/' . $username . '?privatekey=' . $privateKey);
+ $req = $this->getRequest('/' . $username . '?privateKey=' . $privateKey);
$response_body = $req->send()->getBody();
$rss = simplexml_load_string($response_body);
@@ -129,7 +129,7 @@ class www_rssTest extends TestBaseApi
null, 'private bookmark'
);
- $req = $this->getRequest('/' . $username . '?privatekey=' . $privateKey);
+ $req = $this->getRequest('/' . $username . '?privateKey=' . $privateKey);
$cookies = $req->setCookieJar()->getCookieJar();
$response_body = $req->send()->getBody();
diff --git a/www/bookmarks.php b/www/bookmarks.php
index 44119db..7056fa6 100644
--- a/www/bookmarks.php
+++ b/www/bookmarks.php
@@ -276,7 +276,7 @@ if ($templatename == 'editbookmark.tpl') {
$tplVars['rsschannels'],
array(
filter($sitename . $rssTitle. sprintf(T_(': (private) ')) . $currentUsername),
- createURL('rss', filter($currentUsername, 'url') . '?sort='.getSortOrder().'&privatekey='.$currentUser->getPrivateKey())
+ createURL('rss', filter($currentUsername, 'url') . '?sort='.getSortOrder().'&privateKey='.$currentUser->getPrivateKey())
)
);
}
diff --git a/www/index.php b/www/index.php
index 2fa21f8..f270f73 100644
--- a/www/index.php
+++ b/www/index.php
@@ -52,7 +52,7 @@ if ($userservice->isLoggedOn()) {
$tplVars['rsschannels'],
array(
filter(sprintf(T_('%s: Recent bookmarks (+private) %s'), $sitename, $currentUsername)),
- createURL('rss', filter($currentUsername, 'url') . '?sort='.getSortOrder().'&privatekey='.$currentUser->getPrivateKey())
+ createURL('rss', filter($currentUsername, 'url') . '?sort='.getSortOrder().'&privateKey='.$currentUser->getPrivateKey())
)
);
}
diff --git a/www/rss.php b/www/rss.php
index b8f6948..d888726 100644
--- a/www/rss.php
+++ b/www/rss.php
@@ -64,9 +64,9 @@ if (!isset($rssEntries) || $rssEntries <= 0) {
$rssEntries = $maxRssEntries;
}
-$privatekey = null;
-if (isset($_GET['privatekey'])) {
- $privatekey = $_GET['privatekey'];
+$privateKey = null;
+if (isset($_GET['privateKey'])) {
+ $privateKey = $_GET['privateKey'];
}
$userid = null;
@@ -83,10 +83,10 @@ if ($user && $user != 'all') {
} else {
if ($userinfo = $userservice->getUserByUsername($user)) {
$userid =& $userinfo[$userservice->getFieldName('primary')];
- /* if user is not logged in and has valid privatekey */
+ /* if user is not logged in and has valid privateKey */
if (!$userservice->isLoggedOn()) {
- if ($privatekey != null) {
- if (!$userservice->loginPrivateKey($privatekey)) {
+ if ($privateKey != null) {
+ if (!$userservice->loginPrivateKey($privateKey)) {
$tplVars['error'] = sprintf(T_('Failed to Autenticate User with username %s using private key'), $user);
header('Content-type: text/html; charset=utf-8');
$templateservice->loadTemplate('error.404.tpl', $tplVars);
@@ -106,8 +106,8 @@ if ($user && $user != 'all') {
}
$pagetitle .= ": ". $user;
} else {
- if ($privatekey != null) {
- if (!$userservice->loginPrivateKey($privatekey)) {
+ if ($privateKey != null) {
+ if (!$userservice->loginPrivateKey($privateKey)) {
$tplVars['error'] = sprintf(T_('Failed to Autenticate User with username %s using private key'), $user);
header('Content-type: text/html; charset=utf-8');
$templateservice->loadTemplate('error.404.tpl', $tplVars);
diff --git a/www/tags.php b/www/tags.php
index 09725e4..fca8a04 100644
--- a/www/tags.php
+++ b/www/tags.php
@@ -77,7 +77,7 @@ if ($userservice->isLoggedOn()) {
$tplVars['rsschannels'],
array(
filter($sitename .': Tags: '. $cat . sprintf(T_(': (private) ')) . $currentUsername),
- createURL('rss', filter($currentUsername, 'url') . '?sort='.getSortOrder().'&privatekey='.$currentUser->getPrivateKey())
+ createURL('rss', filter($currentUsername, 'url') . '?sort='.getSortOrder().'&privateKey='.$currentUser->getPrivateKey())
)
);
}
--
cgit v1.2.3-54-g00ecf
From 82ee59779ea9a5d2d9234e622f56cfcc4c22ff3a Mon Sep 17 00:00:00 2001
From: Christian Weiske
Date: Thu, 21 Jul 2011 21:32:48 +0200
Subject: support global and per-host configuration files
---
src/SemanticScuttle/Config.php | 109 ++++++++++++++++++
src/SemanticScuttle/header.php | 17 ++-
tests/SemanticScuttle/ConfigTest.php | 206 +++++++++++++++++++++++++++++++++++
3 files changed, 329 insertions(+), 3 deletions(-)
create mode 100644 src/SemanticScuttle/Config.php
create mode 100644 tests/SemanticScuttle/ConfigTest.php
(limited to 'src/SemanticScuttle')
diff --git a/src/SemanticScuttle/Config.php b/src/SemanticScuttle/Config.php
new file mode 100644
index 0000000..0773310
--- /dev/null
+++ b/src/SemanticScuttle/Config.php
@@ -0,0 +1,109 @@
+
+ * @license AGPL http://www.gnu.org/licenses/agpl.html
+ * @link http://sourceforge.net/projects/semanticscuttle
+ */
+
+/**
+ * Configuration handling
+ *
+ * @category Bookmarking
+ * @package SemanticScuttle
+ * @author Christian Weiske
+ * @license AGPL http://www.gnu.org/licenses/agpl.html
+ * @link http://sourceforge.net/projects/semanticscuttle
+ */
+class SemanticScuttle_Config
+{
+ /**
+ * Prefix for configuration files.
+ * Used to inject stream wrapper protocol for unit testing
+ *
+ * @var string
+ */
+ public $filePrefix = '';
+
+
+
+ /**
+ * Finds the correct data directory
+ *
+ * @return string Full path to the data directory with a trailing slash
+ */
+ protected function getDataDir()
+ {
+ if ('@data_dir@' == '@' . 'data_dir@') {
+ //non pear-install
+ $datadir = dirname(__FILE__) . '/../../data/';
+ } else {
+ //pear installation; files are in include path
+ $datadir = '@data_dir@/SemanticScuttle/';
+ }
+
+ return $datadir;
+ }
+
+
+
+ /**
+ * Tries to find a configuration file by looking in different
+ * places:
+ * - pear data_dir/SemanticScuttle/config-$hostname.php
+ * - pear data_dir/SemanticScuttle/config.php
+ * - /etc/semanticscuttle/config-$hostname.php
+ * - /etc/semanticscuttle/config.php
+ *
+ * Paths with host name have priority.
+ *
+ * @return array Array with config file path as first value
+ * and default config file path as second value.
+ * Any may be NULL if not found
+ */
+ public function findFiles()
+ {
+ //use basename to prevent path injection
+ $host = basename($_SERVER['HTTP_HOST']);
+ $datadir = $this->getDataDir();
+
+ $arFiles = array(
+ $datadir . 'config.' . $host . '.php',
+ '/etc/semanticscuttle/config.' . $host . '.php',
+ $datadir . 'config.php',
+ '/etc/semanticscuttle/config.php',
+ );
+
+ $configfile = null;
+ foreach ($arFiles as $file) {
+ if (file_exists($this->filePrefix . $file)) {
+ $configfile = $file;
+ break;
+ }
+ }
+
+ //find default file
+ $arDefaultFiles = array_unique(
+ array(
+ substr($configfile, 0, -3) . 'default.php',
+ $datadir . 'config.default.php',
+ '/etc/semanticscuttle/config.default.php',
+ )
+ );
+ $defaultfile = null;
+ foreach ($arDefaultFiles as $file) {
+ if (file_exists($this->filePrefix . $file)) {
+ $defaultfile = $file;
+ break;
+ }
+ }
+ return array($configfile, $defaultfile);
+ }
+}
+
+?>
\ No newline at end of file
diff --git a/src/SemanticScuttle/header.php b/src/SemanticScuttle/header.php
index 6c0d4df..9252300 100644
--- a/src/SemanticScuttle/header.php
+++ b/src/SemanticScuttle/header.php
@@ -25,8 +25,19 @@ if ('@data_dir@' == '@' . 'data_dir@') {
//FIXME: when you have multiple installations, the www_dir will be wrong
$wwwdir = '@www_dir@/SemanticScuttle/';
}
+require_once dirname(__FILE__) . '/Config.php';
-if (!file_exists($datadir . '/config.php')) {
+$cfg = new SemanticScuttle_Config();
+list($configfile, $defaultfile) = $cfg->findFiles();
+if ($defaultfile === null) {
+ header('HTTP/1.0 500 Internal Server Error');
+ die(
+ 'No default configuration file config.default.php found.'
+ . ' This is really, really strange'
+ . "\n"
+ );
+}
+if ($configfile === null) {
header('HTTP/1.0 500 Internal Server Error');
die(
'Please copy "config.php.dist" to "config.php" in data/ folder.'
@@ -39,8 +50,8 @@ set_include_path(
);
// 1 // First requirements part (before debug management)
-require_once $datadir . '/config.default.php';
-require_once $datadir . '/config.php';
+require_once $defaultfile;
+require_once $configfile;
if (isset($_GET['unittestMode']) && $_GET['unittestMode'] == 1
) {
diff --git a/tests/SemanticScuttle/ConfigTest.php b/tests/SemanticScuttle/ConfigTest.php
new file mode 100644
index 0000000..670f82a
--- /dev/null
+++ b/tests/SemanticScuttle/ConfigTest.php
@@ -0,0 +1,206 @@
+_setPointer($scope, $varpath)) {
+ return false;
+ }
+
+ return parent::url_stat($path, $flags);
+ }
+}
+
+class SemanticScuttle_ConfigTest extends PHPUnit_Framework_TestCase
+{
+ /**
+ * Configuration object to test
+ */
+ protected $cfg;
+
+
+ public function setUpWrapper()
+ {
+ if (!in_array('unittest', stream_get_wrappers())) {
+ stream_wrapper_register(
+ 'unittest', 'SemanticScuttle_ConfigTest_StreamVar'
+ );
+ }
+
+ $this->cfg = $this->getMock(
+ 'SemanticScuttle_Config',
+ array('getDataDir')
+ );
+ $this->cfg->expects($this->once())
+ ->method('getDataDir')
+ ->will($this->returnValue('/data-dir/'));
+
+ $this->cfg->filePrefix = 'unittest://GLOBALS/unittest-dir';
+ }
+
+
+
+ public function testFindLocalData()
+ {
+ $this->setUpWrapper();
+ $GLOBALS['unittest-dir']['data-dir'] = array(
+ 'config.php' => 'content',
+ 'config.default.php' => 'content'
+ );
+ $this->assertEquals(
+ array(
+ '/data-dir/config.php',
+ '/data-dir/config.default.php'
+ ),
+ $this->cfg->findFiles()
+ );
+ }
+
+ public function testFindHostPreferredOverNonHostConfig()
+ {
+ $this->setUpWrapper();
+ $_SERVER['HTTP_HOST'] = 'foo.example.org';
+
+ $GLOBALS['unittest-dir']['data-dir'] = array(
+ 'config.php' => 'content',
+ 'config.foo.example.org.php' => 'content',
+ 'config.default.php' => 'content'
+ );
+ $this->assertEquals(
+ array(
+ '/data-dir/config.foo.example.org.php',
+ '/data-dir/config.default.php'
+ ),
+ $this->cfg->findFiles()
+ );
+ }
+
+ public function testFindEtcHostPreferredOverLocalConfigPhp()
+ {
+ $this->setUpWrapper();
+ $_SERVER['HTTP_HOST'] = 'foo.example.org';
+
+ $GLOBALS['unittest-dir'] = array(
+ 'etc' => array(
+ 'semanticscuttle' => array(
+ 'config.foo.example.org.php' => 'content',
+ )
+ ),
+ 'data-dir' => array(
+ 'config.php' => 'content',
+ 'config.default.php' => 'content'
+ )
+ );
+
+ $this->assertEquals(
+ array(
+ '/etc/semanticscuttle/config.foo.example.org.php',
+ '/data-dir/config.default.php'
+ ),
+ $this->cfg->findFiles()
+ );
+ }
+
+ public function testFindEtcConfig()
+ {
+ $this->setUpWrapper();
+ $GLOBALS['unittest-dir'] = array(
+ 'etc' => array(
+ 'semanticscuttle' => array(
+ 'config.php' => 'content'
+ )
+ ),
+ 'data-dir' => array(
+ 'config.default.php' => 'content'
+ )
+ );
+ $this->assertEquals(
+ array(
+ '/etc/semanticscuttle/config.php',
+ '/data-dir/config.default.php'
+ ),
+ $this->cfg->findFiles()
+ );
+ }
+
+ public function testFindEtcDefaultConfig()
+ {
+ $this->setUpWrapper();
+ $GLOBALS['unittest-dir'] = array(
+ 'etc' => array(
+ 'semanticscuttle' => array(
+ 'config.php' => 'content',
+ 'config.default.php' => 'content'
+ )
+ ),
+ );
+ $this->assertEquals(
+ array(
+ '/etc/semanticscuttle/config.php',
+ '/etc/semanticscuttle/config.default.php'
+ ),
+ $this->cfg->findFiles()
+ );
+ }
+
+ public function testFindLocalDefaultPreferredOverEtcDefault()
+ {
+ $this->setUpWrapper();
+ $GLOBALS['unittest-dir'] = array(
+ 'etc' => array(
+ 'semanticscuttle' => array(
+ 'config.php' => 'content',
+ 'config.default.php' => 'content'
+ )
+ ),
+ 'data-dir' => array(
+ 'config.php' => 'content',
+ 'config.default.php' => 'content'
+ )
+ );
+ $this->assertEquals(
+ array(
+ '/data-dir/config.php',
+ '/data-dir/config.default.php'
+ ),
+ $this->cfg->findFiles()
+ );
+ }
+
+ public function testFindSameDirDefaultPreferred()
+ {
+ $this->setUpWrapper();
+ $GLOBALS['unittest-dir'] = array(
+ 'etc' => array(
+ 'semanticscuttle' => array(
+ 'config.php' => 'content',
+ 'config.default.php' => 'content'
+ )
+ ),
+ 'data-dir' => array(
+ 'config.default.php' => 'content'
+ )
+ );
+ $this->assertEquals(
+ array(
+ '/etc/semanticscuttle/config.php',
+ '/etc/semanticscuttle/config.default.php'
+ ),
+ $this->cfg->findFiles()
+ );
+ }
+
+}
+
+?>
\ No newline at end of file
--
cgit v1.2.3-54-g00ecf
From 0396dee7304c616ecb60c048d4013f917a7087f4 Mon Sep 17 00:00:00 2001
From: Christian Weiske
Date: Sat, 23 Jul 2011 14:07:58 +0200
Subject: fix typo
---
src/SemanticScuttle/constants.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'src/SemanticScuttle')
diff --git a/src/SemanticScuttle/constants.php b/src/SemanticScuttle/constants.php
index f8567d9..11ab0da 100644
--- a/src/SemanticScuttle/constants.php
+++ b/src/SemanticScuttle/constants.php
@@ -74,7 +74,7 @@ if (isset($_SERVER['PATH_INFO']) && isset($_SERVER['ORIG_PATH_INFO'])) {
if (strlen($_SERVER["PATH_INFO"])
+ * @license AGPL http://www.gnu.org/licenses/agpl.html
+ * @link http://sourceforge.net/projects/semanticscuttle
+ */
+
+/**
+ * Server environment handling methods
+ *
+ * @category Bookmarking
+ * @package SemanticScuttle
+ * @author Christian Weiske
+ * @license AGPL http://www.gnu.org/licenses/agpl.html
+ * @link http://sourceforge.net/projects/semanticscuttle
+ */
+class SemanticScuttle_Environment
+{
+ /**
+ * Determines the correct $_SERVER['PATH_INFO'] value
+ *
+ * @return string New value
+ */
+ public static function getServerPathInfo()
+ {
+ /* old code that does not work today.
+ if you find that this code helps you, tell us
+ and send us the output of var_export($_SERVER);
+ // Correct bugs with PATH_INFO (maybe for Apache 1 or CGI) -- for 1&1 host...
+ if (isset($_SERVER['PATH_INFO']) && isset($_SERVER['ORIG_PATH_INFO'])) {
+ if (strlen($_SERVER["PATH_INFO"])
\ No newline at end of file
diff --git a/src/SemanticScuttle/constants.php b/src/SemanticScuttle/constants.php
index 11ab0da..fcb2d90 100644
--- a/src/SemanticScuttle/constants.php
+++ b/src/SemanticScuttle/constants.php
@@ -69,16 +69,6 @@ define('PAGE_WATCHLIST', "watchlist");
// installations on the same host server
define('INSTALLATION_ID', md5($GLOBALS['dbname'].$GLOBALS['tableprefix']));
-// Correct bugs with PATH_INFO (maybe for Apache 1 or CGI) -- for 1&1 host...
-if (isset($_SERVER['PATH_INFO']) && isset($_SERVER['ORIG_PATH_INFO'])) {
- if (strlen($_SERVER["PATH_INFO"])
diff --git a/src/SemanticScuttle/header.php b/src/SemanticScuttle/header.php
index 9252300..694df54 100644
--- a/src/SemanticScuttle/header.php
+++ b/src/SemanticScuttle/header.php
@@ -25,6 +25,7 @@ if ('@data_dir@' == '@' . 'data_dir@') {
//FIXME: when you have multiple installations, the www_dir will be wrong
$wwwdir = '@www_dir@/SemanticScuttle/';
}
+require_once dirname(__FILE__) . '/Environment.php';
require_once dirname(__FILE__) . '/Config.php';
$cfg = new SemanticScuttle_Config();
diff --git a/tests/SemanticScuttle/EnvironmentTest.php b/tests/SemanticScuttle/EnvironmentTest.php
new file mode 100644
index 0000000..a41efa1
--- /dev/null
+++ b/tests/SemanticScuttle/EnvironmentTest.php
@@ -0,0 +1,95 @@
+ 'Opera/9.80 (X11; Linux x86_64; U; de) Presto/2.9.168 Version/11.50',
+ 'HTTP_HOST' => 'bm-cgi.bogo',
+ 'HTTP_ACCEPT' => 'text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1',
+ 'HTTP_ACCEPT_LANGUAGE' => 'de-DE,de;q=0.9,en;q=0.8',
+ 'HTTP_ACCEPT_ENCODING' => 'gzip, deflate',
+ 'HTTP_COOKIE' => 'PHPSESSID=ga446jhs0e09hkt60u9bsmp0n0',
+ 'HTTP_CACHE_CONTROL' => 'no-cache',
+ 'HTTP_CONNECTION' => 'Keep-Alive',
+ 'PATH' => '/usr/local/bin:/usr/bin:/bin',
+ 'SERVER_SIGNATURE' => 'Apache/2.2.17 (Ubuntu) Server at bm-cgi.bogo Port 80',
+ 'SERVER_SOFTWARE' => 'Apache/2.2.17 (Ubuntu)',
+ 'SERVER_NAME' => 'bm-cgi.bogo',
+ 'SERVER_ADDR' => '127.0.0.1',
+ 'SERVER_PORT' => '80',
+ 'REMOTE_ADDR' => '127.0.0.1',
+ 'DOCUMENT_ROOT' => '/etc/apache2/htdocs',
+ 'SERVER_ADMIN' => '[no address given]',
+ 'SCRIPT_FILENAME' => '/home/cweiske/Dev/html/hosts/bm-cgi.bogo/profile.php',
+ 'REMOTE_PORT' => '45349',
+ 'GATEWAY_INTERFACE' => 'CGI/1.1',
+ 'SERVER_PROTOCOL' => 'HTTP/1.1',
+ 'REQUEST_METHOD' => 'GET',
+ 'QUERY_STRING' => '',
+ 'REQUEST_URI' => '/profile.php/dummy',
+ 'SCRIPT_NAME' => '/profile.php',
+ 'PATH_INFO' => '/dummy',
+ 'PATH_TRANSLATED' => '/home/cweiske/Dev/html/hosts/bm-cgi.bogo/dummy',
+ 'PHP_SELF' => '/profile.php/dummy',
+ 'REQUEST_TIME' => 1311422546,
+ );
+ $this->assertEquals(
+ '/dummy', SemanticScuttle_Environment::getServerPathInfo()
+ );
+ }
+
+
+ public function testServerPathInfoFastCgi()
+ {
+ $_SERVER = array(
+ 'PHP_FCGI_MAX_REQUESTS' => '5000',
+ 'PHPRC' => '/etc/php5/cgi/5.3.6/',
+ 'PHP_FCGI_CHILDREN' => '3',
+ 'PWD' => '/var/www/cgi-bin',
+ 'FCGI_ROLE' => 'RESPONDER',
+ 'REDIRECT_HANDLER' => 'php-cgi',
+ 'REDIRECT_STATUS' => '200',
+ 'HTTP_USER_AGENT' => 'Opera/9.80 (X11; Linux x86_64; U; de) Presto/2.9.168 Version/11.50',
+ 'HTTP_HOST' => 'bm-cgi.bogo',
+ 'HTTP_ACCEPT' => 'text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1',
+ 'HTTP_ACCEPT_LANGUAGE' => 'de-DE,de;q=0.9,en;q=0.8',
+ 'HTTP_ACCEPT_ENCODING' => 'gzip, deflate',
+ 'HTTP_COOKIE' => 'PHPSESSID=ga446jhs0e09hkt60u9bsmp0n0',
+ 'HTTP_CONNECTION' => 'Keep-Alive',
+ 'PATH' => '/usr/local/bin:/usr/bin:/bin',
+ 'SERVER_SIGNATURE' => 'Apache/2.2.17 (Ubuntu) Server at bm-cgi.bogo Port 80',
+ 'SERVER_SOFTWARE' => 'Apache/2.2.17 (Ubuntu)',
+ 'SERVER_NAME' => 'bm-cgi.bogo',
+ 'SERVER_ADDR' => '127.0.0.1',
+ 'SERVER_PORT' => '80',
+ 'REMOTE_ADDR' => '127.0.0.1',
+ 'DOCUMENT_ROOT' => '/etc/apache2/htdocs',
+ 'SERVER_ADMIN' => '[no address given]',
+ 'SCRIPT_FILENAME' => '/home/cweiske/Dev/html/hosts/bm-cgi.bogo/profile.php',
+ 'REMOTE_PORT' => '45342',
+ 'REDIRECT_URL' => '/profile.php/dummy',
+ 'GATEWAY_INTERFACE' => 'CGI/1.1',
+ 'SERVER_PROTOCOL' => 'HTTP/1.1',
+ 'REQUEST_METHOD' => 'GET',
+ 'QUERY_STRING' => '',
+ 'REQUEST_URI' => '/profile.php/dummy',
+ 'SCRIPT_NAME' => '/profile.php',
+ 'PATH_INFO' => '/dummy',
+ 'PATH_TRANSLATED' => '/etc/apache2/htdocs/dummy',
+ 'ORIG_PATH_INFO' => '/profile.php/dummy',
+ 'ORIG_SCRIPT_NAME' => '/cgi-bin-php/php-cgi-5.3.6',
+ 'ORIG_SCRIPT_FILENAME' => '/var/www/cgi-bin/php-cgi-5.3.6',
+ 'ORIG_PATH_TRANSLATED' => '/home/cweiske/Dev/html/hosts/bm-cgi.bogo/profile.php/dummy',
+ 'PHP_SELF' => '/profile.php/dummy',
+ 'REQUEST_TIME' => 1311422521,
+ );
+ $this->assertEquals(
+ '/dummy', SemanticScuttle_Environment::getServerPathInfo()
+ );
+ }
+
+}
+
+?>
\ No newline at end of file
--
cgit v1.2.3-54-g00ecf