unify hashing code in a separate method
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@692 b3834d28-1941-0410-a4f8-b48e95affb8f
This commit is contained in:
parent
8c213f0e6e
commit
602ec95bbb
2 changed files with 42 additions and 25 deletions
|
@ -178,9 +178,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
|
||||||
*/
|
*/
|
||||||
public function getBookmarkByAddress($address)
|
public function getBookmarkByAddress($address)
|
||||||
{
|
{
|
||||||
$address = $this->normalize($address);
|
return $this->getBookmarkByHash($this->getHash($address));
|
||||||
$hash = md5($address);
|
|
||||||
return $this->getBookmarkByHash($hash);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -189,10 +187,12 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
|
||||||
* Retrieves a bookmark with the given hash.
|
* Retrieves a bookmark with the given hash.
|
||||||
* DOES NOT RESPECT PRIVACY SETTINGS!
|
* DOES NOT RESPECT PRIVACY SETTINGS!
|
||||||
*
|
*
|
||||||
* @param string $hash URL hash (MD5)
|
* @param string $hash URL hash
|
||||||
*
|
*
|
||||||
* @return mixed Array with bookmark data or false in case
|
* @return mixed Array with bookmark data or false in case
|
||||||
* of an error (i.e. not found).
|
* of an error (i.e. not found).
|
||||||
|
*
|
||||||
|
* @see getHash()
|
||||||
*/
|
*/
|
||||||
public function getBookmarkByHash($hash)
|
public function getBookmarkByHash($hash)
|
||||||
{
|
{
|
||||||
|
@ -201,6 +201,25 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the hash value of a given address.
|
||||||
|
*
|
||||||
|
* @param string $address URL to hash
|
||||||
|
* @param boolean $bNormalize If the address shall be normalized before
|
||||||
|
* being hashed
|
||||||
|
*
|
||||||
|
* @return string Hash value
|
||||||
|
*/
|
||||||
|
public function getHash($address, $bNormalize = true)
|
||||||
|
{
|
||||||
|
if ($bNormalize) {
|
||||||
|
$address = $this->normalize($address);
|
||||||
|
}
|
||||||
|
return md5($address);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a bookmark that has a given short
|
* Retrieves a bookmark that has a given short
|
||||||
* name.
|
* name.
|
||||||
|
@ -319,9 +338,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$address = $this->normalize($address);
|
$crit = array('bHash' => $this->getHash($address));
|
||||||
|
|
||||||
$crit = array('bHash' => md5($address));
|
|
||||||
if (isset ($uid)) {
|
if (isset ($uid)) {
|
||||||
$crit['uId'] = $uid;
|
$crit['uId'] = $uid;
|
||||||
}
|
}
|
||||||
|
@ -365,7 +382,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
|
||||||
$hashes = array();
|
$hashes = array();
|
||||||
$sql = '(1';
|
$sql = '(1';
|
||||||
foreach ($addresses as $key => $address) {
|
foreach ($addresses as $key => $address) {
|
||||||
$hash = md5($this->normalize($address));
|
$hash = $this->getHash($address);
|
||||||
$hashes[$hash] = $address;
|
$hashes[$hash] = $address;
|
||||||
$sql .= ' OR bHash = "'
|
$sql .= ' OR bHash = "'
|
||||||
. $this->db->sql_escape($hash)
|
. $this->db->sql_escape($hash)
|
||||||
|
@ -471,7 +488,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
|
||||||
'bDescription' => $description,
|
'bDescription' => $description,
|
||||||
'bPrivateNote' => $privateNote,
|
'bPrivateNote' => $privateNote,
|
||||||
'bStatus' => intval($status),
|
'bStatus' => intval($status),
|
||||||
'bHash' => md5($address),
|
'bHash' => $this->getHash($address),
|
||||||
'bShort' => $short
|
'bShort' => $short
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -588,7 +605,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
|
||||||
'bDescription' => $description,
|
'bDescription' => $description,
|
||||||
'bPrivateNote' => $privateNote,
|
'bPrivateNote' => $privateNote,
|
||||||
'bStatus' => $status,
|
'bStatus' => $status,
|
||||||
'bHash' => md5($address),
|
'bHash' => $this->getHash($address, false),
|
||||||
'bShort' => $short
|
'bShort' => $short
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1004,7 +1021,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
|
||||||
$addressesSql = ' AND (0';
|
$addressesSql = ' AND (0';
|
||||||
foreach ((array)$addresses as $address) {
|
foreach ((array)$addresses as $address) {
|
||||||
$addressesSql .= ' OR B.bHash = "'
|
$addressesSql .= ' OR B.bHash = "'
|
||||||
. $this->db->sql_escape(md5($address))
|
. $this->db->sql_escape($this->getHash($address))
|
||||||
. '"';
|
. '"';
|
||||||
}
|
}
|
||||||
$addressesSql .= ')';
|
$addressesSql .= ')';
|
||||||
|
|
|
@ -167,7 +167,7 @@ if ($userservice->isLoggedOn() && POST_SUBMITTED != '') {
|
||||||
if (GET_ACTION == "add") {
|
if (GET_ACTION == "add") {
|
||||||
// If the bookmark exists already, edit the original
|
// If the bookmark exists already, edit the original
|
||||||
if ($bookmarkservice->bookmarkExists(stripslashes(GET_ADDRESS), $currentUserID)) {
|
if ($bookmarkservice->bookmarkExists(stripslashes(GET_ADDRESS), $currentUserID)) {
|
||||||
$bookmark =& $bookmarkservice->getBookmarks(0, NULL, $currentUserID, NULL, NULL, NULL, NULL, NULL, NULL, md5($bookmarkservice->normalize(stripslashes(GET_ADDRESS))));
|
$bookmark =& $bookmarkservice->getBookmarks(0, NULL, $currentUserID, NULL, NULL, NULL, NULL, NULL, NULL, $bookmarkservice->getHash(stripslashes(GET_ADDRESS)));
|
||||||
$popup = (GET_POPUP!='') ? '?popup=1' : '';
|
$popup = (GET_POPUP!='') ? '?popup=1' : '';
|
||||||
header('Location: '. createURL('edit', $bookmark['bookmarks'][0]['bId'] . $popup));
|
header('Location: '. createURL('edit', $bookmark['bookmarks'][0]['bId'] . $popup));
|
||||||
exit();
|
exit();
|
||||||
|
|
Loading…
Reference in a new issue