aboutsummaryrefslogtreecommitdiff
path: root/src/SemanticScuttle/Service
diff options
context:
space:
mode:
authorcweiske <cweiske@b3834d28-1941-0410-a4f8-b48e95affb8f>2010-03-18 19:24:21 +0000
committercweiske <cweiske@b3834d28-1941-0410-a4f8-b48e95affb8f>2010-03-18 19:24:21 +0000
commit602ec95bbb91400b6ef2647df55e83e68f4223b5 (patch)
tree57dd77de58d72d0eb2ef3af7ff4dd076191b2b4f /src/SemanticScuttle/Service
parent8c213f0e6e97351a64168aab18d69324a90e7b83 (diff)
downloadsemanticscuttle-602ec95bbb91400b6ef2647df55e83e68f4223b5.tar.gz
semanticscuttle-602ec95bbb91400b6ef2647df55e83e68f4223b5.tar.bz2
unify hashing code in a separate method
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@692 b3834d28-1941-0410-a4f8-b48e95affb8f
Diffstat (limited to 'src/SemanticScuttle/Service')
-rw-r--r--src/SemanticScuttle/Service/Bookmark.php65
1 files changed, 41 insertions, 24 deletions
diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php
index 3cdec72..2258625 100644
--- a/src/SemanticScuttle/Service/Bookmark.php
+++ b/src/SemanticScuttle/Service/Bookmark.php
@@ -178,9 +178,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
*/
public function getBookmarkByAddress($address)
{
- $address = $this->normalize($address);
- $hash = md5($address);
- return $this->getBookmarkByHash($hash);
+ return $this->getBookmarkByHash($this->getHash($address));
}
@@ -189,10 +187,12 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
* Retrieves a bookmark with the given hash.
* 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
* of an error (i.e. not found).
+ *
+ * @see getHash()
*/
public function getBookmarkByHash($hash)
{
@@ -202,6 +202,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
* name.
*
@@ -319,9 +338,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
return false;
}
- $address = $this->normalize($address);
-
- $crit = array('bHash' => md5($address));
+ $crit = array('bHash' => $this->getHash($address));
if (isset ($uid)) {
$crit['uId'] = $uid;
}
@@ -365,7 +382,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
$hashes = array();
$sql = '(1';
foreach ($addresses as $key => $address) {
- $hash = md5($this->normalize($address));
+ $hash = $this->getHash($address);
$hashes[$hash] = $address;
$sql .= ' OR bHash = "'
. $this->db->sql_escape($hash)
@@ -462,17 +479,17 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
// Set up the SQL insert statement and execute it.
$values = array(
- 'uId' => intval($sId),
- 'bIp' => $ip,
- 'bDatetime' => $datetime,
- 'bModified' => $datetime,
- 'bTitle' => $title,
- 'bAddress' => $address,
+ 'uId' => intval($sId),
+ 'bIp' => $ip,
+ 'bDatetime' => $datetime,
+ 'bModified' => $datetime,
+ 'bTitle' => $title,
+ 'bAddress' => $address,
'bDescription' => $description,
'bPrivateNote' => $privateNote,
- 'bStatus' => intval($status),
- 'bHash' => md5($address),
- 'bShort' => $short
+ 'bStatus' => intval($status),
+ 'bHash' => $this->getHash($address),
+ 'bShort' => $short
);
$sql = 'INSERT INTO '. $this->getTableName()
@@ -582,14 +599,14 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
// Set up the SQL update statement and execute it.
$updates = array(
- 'bModified' => $moddatetime,
- 'bTitle' => $title,
- 'bAddress' => $address,
+ 'bModified' => $moddatetime,
+ 'bTitle' => $title,
+ 'bAddress' => $address,
'bDescription' => $description,
'bPrivateNote' => $privateNote,
- 'bStatus' => $status,
- 'bHash' => md5($address),
- 'bShort' => $short
+ 'bStatus' => $status,
+ 'bHash' => $this->getHash($address, false),
+ 'bShort' => $short
);
if (!is_null($date)) {
@@ -1004,7 +1021,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
$addressesSql = ' AND (0';
foreach ((array)$addresses as $address) {
$addressesSql .= ' OR B.bHash = "'
- . $this->db->sql_escape(md5($address))
+ . $this->db->sql_escape($this->getHash($address))
. '"';
}
$addressesSql .= ')';