Cleaned up User.php and moved Private Key function to it

This commit is contained in:
Mark Pemberton 2011-02-02 23:16:23 -05:00
parent a32c9a1578
commit 43ad8e7725
5 changed files with 413 additions and 141 deletions

View File

@ -66,6 +66,13 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
return $instance;
}
/**
* Construct of Class
*
* @param sql_db $db Database object
*
* @return void
*/
protected function __construct($db)
{
$this->db = $db;
@ -87,7 +94,8 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
protected function _getuser($fieldname, $value)
{
$query = 'SELECT * FROM '. $this->getTableName()
. ' WHERE ' . $fieldname . ' = "' . $this->db->sql_escape($value) . '"';
. ' WHERE ' . $fieldname . ' = "'
. $this->db->sql_escape($value) . '"';
if (!($dbresult = $this->db->sql_query($query)) ) {
message_die(
@ -106,13 +114,25 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
}
}
function & getUsers($nb=0) {
/**
* Fetches the list of users from the database
* optionally limiting the results set
*
* @param integer $nb Max number of usrs
*
* @return array Array of users
*/
function & getUsers($nb = 0)
{
$query = 'SELECT * FROM '. $this->getTableName() .' ORDER BY `uId` DESC';
if($nb>0) {
if ($nb>0) {
$query .= ' LIMIT 0, '.$nb;
}
if (! ($dbresult =& $this->db->sql_query($query)) ) {
message_die(GENERAL_ERROR, 'Could not get user', '', __LINE__, __FILE__, $query, $this->db);
if (!($dbresult =& $this->db->sql_query($query))) {
message_die(
GENERAL_ERROR, 'Could not get user', '',
__LINE__, __FILE__, $query, $this->db
);
return false;
}
@ -159,7 +179,13 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
return $users;
}
function _randompassword() {
/**
* Generate a Random Password
*
* @return string random password
*/
function _randompassword()
{
$seed = (integer) md5(microtime());
mt_srand($seed);
$password = mt_rand(1, 99999999);
@ -167,15 +193,30 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
return $password;
}
function _updateuser($uId, $fieldname, $value) {
/**
* Update Specific field on User Record
*
* @param integer $uId User ID
* @param string $fieldname Field Name
* @param string $value Value
*
* @return boolean true if a user is logged in
*/
function _updateuser($uId, $fieldname, $value)
{
$updates = array ($fieldname => $value);
$sql = 'UPDATE '. $this->getTableName() .' SET '. $this->db->sql_build_array('UPDATE', $updates) .' WHERE '. $this->getFieldName('primary') .'='. intval($uId);
$sql = 'UPDATE '. $this->getTableName() .' SET '
. $this->db->sql_build_array('UPDATE', $updates) .' WHERE '
. $this->getFieldName('primary') .'='. intval($uId);
// Execute the statement.
$this->db->sql_transaction('begin');
if (!($dbresult = & $this->db->sql_query($sql))) {
$this->db->sql_transaction('rollback');
message_die(GENERAL_ERROR, 'Could not update user', '', __LINE__, __FILE__, $sql, $this->db);
message_die(
GENERAL_ERROR, 'Could not update user', '',
__LINE__, __FILE__, $sql, $this->db
);
return false;
}
$this->db->sql_transaction('commit');
@ -184,37 +225,68 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
return true;
}
function getProfileUrl($id, $username) {
/**
* Generate Profile URL
*
* @param integer $id User ID
* @param string $username User Name
*
* @return string Profile URL
*/
function getProfileUrl($id, $username)
{
return sprintf($this->profileurl, urlencode($id), urlencode($username));
}
function getUserByUsername($username) {
/**
* Returns user row from database.
*
* @param string $username User Name
*
* @return array User array from database
*/
function getUserByUsername($username)
{
return $this->_getuser($this->getFieldName('username'), $username);
}
function getObjectUserByUsername($username) {
/**
* Returns user row from database.
*
* @param string $username User Name
*
* @return array User array from database, else null
*/
function getObjectUserByUsername($username)
{
$user = $this->_getuser($this->getFieldName('username'), $username);
if($user != false) {
if ($user != false) {
return new SemanticScuttle_Model_User(
$user[$this->getFieldName('primary')], $username
);
} else {
return NULL;
return null;
}
}
/* Takes an numerical "id" or a string "username"
and returns the numerical "id" if the user exists else returns NULL */
function getIdFromUser($user) {
/**
* Returns user ID from database.
*
* @param integer|string $user User ID or user name
*
* @return mixed integer ID of user if exists, else null
*/
function getIdFromUser($user)
{
if (is_int($user)) {
return intval($user);
} else {
$objectUser = $this->getObjectUserByUsername($user);
if($objectUser != NULL) {
if ($objectUser != null) {
return $objectUser->getId();
}
}
return NULL;
return null;
}
/**
@ -244,7 +316,13 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
);
}
function isLoggedOn() {
/**
* Checks if there is a user logged in
*
* @return boolean true if a user is logged in
*/
function isLoggedOn()
{
return ($this->getCurrentUserId() !== false);
}
@ -299,16 +377,32 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
return $currentObjectUser;
}
function existsUserWithUsername($username) {
if($this->getUserByUsername($username) != '') {
/**
* Checks if the given user exists
*
* @param string $username User Name
*
* @return boolean true if the user exists
*/
function existsUserWithUsername($username)
{
if ($this->getUserByUsername($username) != '') {
return true;
} else {
return false;
}
}
function existsUser($id) {
if($this->getUser($id) != '') {
/**
* Checks if the given user exists
*
* @param integer $id User ID
*
* @return boolean true if the user exists
*/
function existsUser($id)
{
if ($this->getUser($id) != '') {
return true;
} else {
return false;
@ -327,7 +421,7 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
* @param integer|array|string $user User ID or user row from DB
* or user name
*
* @return boolean True if the user is admin
* @return boolean true if the user is admin
*/
function isAdmin($user)
{
@ -391,11 +485,10 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
/**
* Set the current user ID (i.e. when logging on)
*
* @internal
* No ID verification is being done.
*
* @param integer $user User ID or null to unset the user
*
* @internal No ID verification is being done.
*
* @return void
*/
public function setCurrentUserId($user)
@ -420,13 +513,18 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
* @param string $password Password
* @param boolean $remember If a long-time cookie shall be set
*
* @return boolean True if the user could be authenticated,
* @return boolean true if the user could be authenticated,
* false if not.
*/
public function login($username, $password, $remember = false)
{
$password = $this->sanitisePassword($password);
$query = 'SELECT '. $this->getFieldName('primary') .' FROM '. $this->getTableName() .' WHERE '. $this->getFieldName('username') .' = "'. $this->db->sql_escape($username) .'" AND '. $this->getFieldName('password') .' = "'. $this->db->sql_escape($password) .'"';
$query = 'SELECT '. $this->getFieldName('primary') .' FROM '
. $this->getTableName() .' WHERE '
. $this->getFieldName('username') .' = "'
. $this->db->sql_escape($username) .'" AND '
. $this->getFieldName('password') .' = "'
. $this->db->sql_escape($password) .'"';
if (!($dbresult = $this->db->sql_query($query))) {
message_die(
@ -456,19 +554,37 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
}
}
function logout() {
/**
* Logout current user
*
* @return void
*/
function logout()
{
@setcookie($this->getCookiekey(), '', time() - 1, '/');
unset($_COOKIE[$this->getCookiekey()]);
session_unset();
$this->getCurrentUser(TRUE, false);
$this->getCurrentUser(true, false);
}
function getWatchlist($uId) {
// Gets the list of user IDs being watched by the given user.
$query = 'SELECT watched FROM '. $GLOBALS['tableprefix'] .'watched WHERE uId = '. intval($uId);
/**
* Gets the list of user IDs being watched by the given user.
*
* @param string $uId Current User ID
*
* @return mixed array if valid query and generates data
* boolean false if an error occured
*/
function getWatchlist($uId)
{
$query = 'SELECT watched FROM '. $GLOBALS['tableprefix']
.'watched WHERE uId = '. intval($uId);
if (! ($dbresult =& $this->db->sql_query($query)) ) {
message_die(GENERAL_ERROR, 'Could not get watchlist', '', __LINE__, __FILE__, $query, $this->db);
message_die(
GENERAL_ERROR, 'Could not get watchlist', '',
__LINE__, __FILE__, $query, $this->db
);
return false;
}
@ -484,10 +600,19 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
return $arrWatch;
}
function getWatchNames($uId, $watchedby = false) {
// Gets the list of user names being watched by the given user.
// - If $watchedby is false get the list of users that $uId watches
// - If $watchedby is true get the list of users that watch $uId
/**
* Gets the list of user names being watched by the given user.
*
* @param string $uId Current User ID
* @param boolean $watchedby flag to determine:
* - If $watchedby is false get the list of users that $uId watches
* - If $watchedby is true get the list of users that watch $uId
*
* @return mixed array if valid query and generates data
* boolean false if an error occured
*/
function getWatchNames($uId, $watchedby = false)
{
if ($watchedby) {
$table1 = 'b';
$table2 = 'a';
@ -495,10 +620,20 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
$table1 = 'a';
$table2 = 'b';
}
$query = 'SELECT '. $table1 .'.'. $this->getFieldName('username') .' FROM '. $GLOBALS['tableprefix'] .'watched AS W, '. $this->getTableName() .' AS a, '. $this->getTableName() .' AS b WHERE W.watched = a.'. $this->getFieldName('primary') .' AND W.uId = b.'. $this->getFieldName('primary') .' AND '. $table2 .'.'. $this->getFieldName('primary') .' = '. intval($uId) .' ORDER BY '. $table1 .'.'. $this->getFieldName('username');
$query = 'SELECT '. $table1 .'.'. $this->getFieldName('username')
.' FROM '. $GLOBALS['tableprefix'] .'watched AS W, '
. $this->getTableName() .' AS a, '. $this->getTableName()
.' AS b WHERE W.watched = a.'. $this->getFieldName('primary')
.' AND W.uId = b.'. $this->getFieldName('primary') .' AND '
. $table2 .'.'. $this->getFieldName('primary') .' = '
. intval($uId) .' ORDER BY '. $table1 .'.'
. $this->getFieldName('username');
if (!($dbresult =& $this->db->sql_query($query))) {
message_die(GENERAL_ERROR, 'Could not get watchlist', '', __LINE__, __FILE__, $query, $this->db);
message_die(
GENERAL_ERROR, 'Could not get watchlist', '',
__LINE__, __FILE__, $query, $this->db
);
return false;
}
@ -514,34 +649,67 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
return $arrWatch;
}
function getWatchStatus($watcheduser, $currentuser) {
// Returns true if the current user is watching the given user, and false otherwise.
$query = 'SELECT watched FROM '. $GLOBALS['tableprefix'] .'watched AS W INNER JOIN '. $this->getTableName() .' AS U ON U.'. $this->getFieldName('primary') .' = W.watched WHERE U.'. $this->getFieldName('primary') .' = '. intval($watcheduser) .' AND W.uId = '. intval($currentuser);
/**
* Get Watch Status
*
* @param string $watcheduser User ID that is being Watched
* @param string $currentuser Current User ID
*
* @return boolean true if it successful, false if not
*/
function getWatchStatus($watcheduser, $currentuser)
{
// Returns true if the current user is watching
// the given user, and false otherwise.
$query = 'SELECT watched FROM '. $GLOBALS['tableprefix']
.'watched AS W INNER JOIN '. $this->getTableName()
.' AS U ON U.'. $this->getFieldName('primary')
.' = W.watched WHERE U.'. $this->getFieldName('primary')
.' = '. intval($watcheduser) .' AND W.uId = '
. intval($currentuser);
if (! ($dbresult =& $this->db->sql_query($query)) ) {
message_die(GENERAL_ERROR, 'Could not get watchstatus', '', __LINE__, __FILE__, $query, $this->db);
message_die(
GENERAL_ERROR, 'Could not get watchstatus', '',
__LINE__, __FILE__, $query, $this->db
);
return false;
}
$arrWatch = array();
if ($this->db->sql_numrows($dbresult) == 0)
return false;
else
return true;
if ($this->db->sql_numrows($dbresult) == 0) {
return false;
} else {
return true;
}
}
function setWatchStatus($subjectUserID) {
if (!is_numeric($subjectUserID))
return false;
/**
* Set Watch Status
*
* @param string $subjectUserID User ID to Watch
*
* @return boolean true if it successful, false if not
*/
function setWatchStatus($subjectUserID)
{
if (!is_numeric($subjectUserID)) {
return false;
}
$currentUserID = $this->getCurrentUserId();
$watched = $this->getWatchStatus($subjectUserID, $currentUserID);
if ($watched) {
$sql = 'DELETE FROM '. $GLOBALS['tableprefix'] .'watched WHERE uId = '. intval($currentUserID) .' AND watched = '. intval($subjectUserID);
$sql = 'DELETE FROM '. $GLOBALS['tableprefix']
.'watched WHERE uId = '. intval($currentUserID)
.' AND watched = '. intval($subjectUserID);
if (!($dbresult =& $this->db->sql_query($sql))) {
$this->db->sql_transaction('rollback');
message_die(GENERAL_ERROR, 'Could not add user to watch list', '', __LINE__, __FILE__, $sql, $this->db);
message_die(
GENERAL_ERROR, 'Could not add user to watch list',
'', __LINE__, __FILE__, $sql, $this->db
);
return false;
}
} else {
@ -549,10 +717,14 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
'uId' => intval($currentUserID),
'watched' => intval($subjectUserID)
);
$sql = 'INSERT INTO '. $GLOBALS['tableprefix'] .'watched '. $this->db->sql_build_array('INSERT', $values);
$sql = 'INSERT INTO '. $GLOBALS['tableprefix'] .'watched '
. $this->db->sql_build_array('INSERT', $values);
if (!($dbresult =& $this->db->sql_query($sql))) {
$this->db->sql_transaction('rollback');
message_die(GENERAL_ERROR, 'Could not add user to watch list', '', __LINE__, __FILE__, $sql, $this->db);
message_die(
GENERAL_ERROR, 'Could not add user to watch list',
'', __LINE__, __FILE__, $sql, $this->db
);
return false;
}
}
@ -566,24 +738,30 @@ 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);
// set new private key if null
if ($privateKey == null) {
$privateKey = $this->getNewPrivateKey();
}
$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);
@ -604,23 +782,51 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
return $uId;
}
function updateUser($uId, $password, $name, $privateKey, $email, $homepage, $uContent) {
if (!is_numeric($uId))
return false;
/**
* Update User Record
*
* @param string $uId User ID
* @param string $password User Password
* @param string $name User Name
* @param string $privateKey RSS Private Key
* @param string $email Email Address
* @param string $homepage Homepage URL
* @param string $uContent Content
*
* @return boolean true if it successful, false if not
*/
function updateUser(
$uId, $password, $name, $privateKey, $email, $homepage, $uContent
) {
if (!is_numeric($uId)) {
return false;
}
// 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, 'privateKey' => $privateKey);
else
$updates = array ('uModified' => $moddatetime, 'password' => $this->sanitisePassword($password), 'name' => $name, 'email' => $email, 'homepage' => $homepage, 'uContent' => $uContent, 'privateKey' => $privateKey);
$sql = 'UPDATE '. $this->getTableName() .' SET '. $this->db->sql_build_array('UPDATE', $updates) .' WHERE '. $this->getFieldName('primary') .'='. intval($uId);
if ($password == '') {
$updates = array (
'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, 'privateKey' => $privateKey);
}
$sql = 'UPDATE '. $this->getTableName() .' SET '
. $this->db->sql_build_array('UPDATE', $updates) .' WHERE '
. $this->getFieldName('primary') .'='. intval($uId);
// Execute the statement.
$this->db->sql_transaction('begin');
if (!($dbresult = & $this->db->sql_query($sql))) {
$this->db->sql_transaction('rollback');
message_die(GENERAL_ERROR, 'Could not update user', '', __LINE__, __FILE__, $sql, $this->db);
message_die(
GENERAL_ERROR, 'Could not update user', '',
__LINE__, __FILE__, $sql, $this->db
);
return false;
}
$this->db->sql_transaction('commit');
@ -629,17 +835,26 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
return true;
}
function getAllUsers ( ) {
/**
* Get list of All Users
*
* @return array List of Users
*/
function getAllUsers ()
{
$query = 'SELECT * FROM '. $this->getTableName();
if (! ($dbresult =& $this->db->sql_query($query)) ) {
message_die(GENERAL_ERROR, 'Could not get users', '', __LINE__, __FILE__, $query, $this->db);
message_die(
GENERAL_ERROR, 'Could not get users', '',
__LINE__, __FILE__, $query, $this->db
);
return false;
}
$rows = array();
while ( $row = $this->db->sql_fetchrow($dbresult) ) {
while ($row = $this->db->sql_fetchrow($dbresult)) {
$rows[] = $row;
}
$this->db->sql_freeresult($dbresult);
@ -647,20 +862,39 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
}
// Returns an array with admin uIds
function getAdminIds() {
/**
* Get list of Admin IDs
*
* @return array Admins Admin IDs
*/
function getAdminIds()
{
$admins = array();
foreach($GLOBALS['admin_users'] as $adminName) {
if($this->getIdFromUser($adminName) != NULL)
$admins[] = $this->getIdFromUser($adminName);
foreach ($GLOBALS['admin_users'] as $adminName) {
if ($this->getIdFromUser($adminName) != null) {
$admins[] = $this->getIdFromUser($adminName);
}
}
return $admins;
}
function deleteUser($uId) {
$query = 'DELETE FROM '. $this->getTableName() .' WHERE uId = '. intval($uId);
/**
* Delete a user based on user ID
*
* @param string $uId User ID
*
* @return boolean true if it successful, false if not
*/
function deleteUser($uId)
{
$query = 'DELETE FROM '. $this->getTableName() .
' WHERE uId = '. intval($uId);
if (!($dbresult = & $this->db->sql_query($query))) {
message_die(GENERAL_ERROR, 'Could not delete user', '', __LINE__, __FILE__, $query, $this->db);
message_die(
GENERAL_ERROR, 'Could not delete user',
'', __LINE__, __FILE__, $query, $this->db
);
return false;
}
@ -722,15 +956,31 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
}
/**
* Generates a new private key and confirms it isn't being used
*
* @return string the new key value
*/
public function getNewPrivateKey()
{
// Generate a 32 char lowercase+numeric unique value
$newKey = md5(uniqid('SemanticScuttle', true));
// Check uniqueness in user table
while ($this->PrivateKeyExists($newKey)) {
$newKey = md5(uniqid('SemanticScuttle', true));
}
return $newKey;
}
/**
* Checks if a private key already exists
*
* @param string $privateKey key that has been generated
* @param string $privateKey key that has been generated
*
* @return boolean True when the private key exists,
* @return boolean true when the private key exists,
* False if not.
*/
public function PrivateKeyExists($privateKey)
public function privateKeyExists($privateKey)
{
if (!$privateKey) {
return false;
@ -756,7 +1006,15 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
return $output;
}
function isReserved($username) {
/**
* Checks if the given username is a reserved username
*
* @param string $username User Name
*
* @return boolean true if it is valid, false if not
*/
function isReserved($username)
{
if (in_array($username, $GLOBALS['reservedusers'])) {
return true;
} else {
@ -764,11 +1022,20 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
}
}
function isValidUsername($username) {
/**
* Checks if the given username is valid
*
* @param string $username User Name
*
* @return boolean true if it is valid, false if not
*/
function isValidUsername($username)
{
if (strlen($username) < 4) {
return false;
}elseif (strlen($username) > 24) {
// too long usernames are cut by database and may cause bugs when compared
} elseif (strlen($username) > 24) {
// too long usernames are cut by database
//and may cause bugs when compared
return false;
} elseif (preg_match('/(\W)/', $username) > 0) {
// forbidden non-alphanumeric characters
@ -777,14 +1044,12 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
return true;
}
/**
* Checks if the given email address is valid
*
* @param string $email Email address
*
* @return boolean True if it is valid, false if not
* @return boolean true if it is valid, false if not
*/
public function isValidEmail($email)
{
@ -816,7 +1081,7 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
* call with that session id. If the session is old,
* we know that cookies (or session persistance) works
*
* @return boolean True if the
* @return boolean true if the
*
* @see updateSessionStability()
*/
@ -852,11 +1117,49 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
$this->fields[$field] = $value;
}
function getSessionKey() { return $this->sessionkey; }
function setSessionKey($value) { $this->sessionkey = $value; }
/**
* Get session key
*
* @return string Value
*/
function getSessionKey()
{
return $this->sessionkey;
}
function getCookieKey() { return $this->cookiekey; }
function setCookieKey($value) { $this->cookiekey = $value; }
/**
* Set session key
*
* @param string $value Session Key
*
* @return void
*/
function setSessionKey($value)
{
$this->sessionkey = $value;
}
/**
* Get cookie key
*
* @return string Value
*/
function getCookieKey()
{
return $this->cookiekey;
}
/**
* Set cookie key
*
* @param string $value Cookie Key
*
* @return void
*/
function setCookieKey($value)
{
$this->cookiekey = $value;
}
}
?>

View File

@ -106,4 +106,4 @@ class TestBase extends PHPUnit_Framework_TestCase
}
?>
?>

View File

@ -114,4 +114,4 @@ class TestBaseApi extends TestBase
}
}
?>
?>

View File

@ -3,27 +3,14 @@
# (see $cleanurls in config.inc.php)
#####################################
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^bookmarks/(\d+)*$ ./bookmarks.php?id=$1
RewriteRule ^users/(\d+)*$ ./profile.php?id=$1
RewriteRule ^alltags/(\d+)*$ ./alltags.php?id=$1
RewriteRule ^search/(.*)$ ./search.php?query=$1
# Rewrite clean URLs onto real files
#<IfModule mod_rewrite.c>
#Options +FollowSymlinks
#RewriteEngine On
#RewriteCond %{REQUEST_FILENAME}.php -f
#RewriteRule ^([^/.]+)/?(.*)$ /$1.php/$2 [QSA,L]
#RewriteRule ^api/([a-z]+)/([a-z]+) /api/$1_$2.php
#</IfModule>
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^/.]+)/?(.*)$ /$1.php/$2 [QSA,L]
RewriteRule ^api/([a-z]+)/([a-z]+) /api/$1_$2.php
</IfModule>
#####################################

View File

@ -30,24 +30,6 @@ $us = SemanticScuttle_Service_Factory::get('User');
/* Managing all possible inputs */
isset($_GET['url']) ? define('GET_URL', $_GET['url']): define('GET_URL', '');
/**
* Generates a new private key and confirms it isn't being used
*
* @return string the new key value
*/
function getNewPrivateKey()
{
global $us;
// Generate a 32 char lowercase+numeric unique value
$newKey = md5(uniqid('SemanticScuttle',True));
// Check uniqueness in user table
while ($us->PrivateKeyExists($newKey)) {
$newKey = md5(uniqid('SemanticScuttle',True));
}
return $newKey;
}
echo '<?xml version="1.0" encoding="utf-8"?>';
?>
<response>
@ -55,6 +37,6 @@ echo '<?xml version="1.0" encoding="utf-8"?>';
getNewPrivateKey
</method>
<result>
<?php echo getNewPrivateKey(); ?>
<?php echo $us->getNewPrivateKey(); ?>
</result>
</response>