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
---
www/ajaxGetNewPrivateKey.php | 42 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
create mode 100644 www/ajaxGetNewPrivateKey.php
(limited to 'www/ajaxGetNewPrivateKey.php')
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 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 'www/ajaxGetNewPrivateKey.php')
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