summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcweiske <cweiske@b3834d28-1941-0410-a4f8-b48e95affb8f>2010-09-23 07:34:47 +0000
committercweiske <cweiske@b3834d28-1941-0410-a4f8-b48e95affb8f>2010-09-23 07:34:47 +0000
commit647a13499e5fa56f8de39504547cef8a2d89b8ff (patch)
tree56d698706999308bbbd34af2842146d53804f279
parent6fb920199695b4b595ec15aad73039eac0feca60 (diff)
downloadsemanticscuttle-647a13499e5fa56f8de39504547cef8a2d89b8ff.tar.gz
semanticscuttle-647a13499e5fa56f8de39504547cef8a2d89b8ff.tar.bz2
Move user IP resolution into own class method
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@747 b3834d28-1941-0410-a4f8-b48e95affb8f
-rw-r--r--src/SemanticScuttle/Model/RemoteUser.php48
-rw-r--r--src/SemanticScuttle/Service/Bookmark.php21
2 files changed, 51 insertions, 18 deletions
diff --git a/src/SemanticScuttle/Model/RemoteUser.php b/src/SemanticScuttle/Model/RemoteUser.php
new file mode 100644
index 0000000..6d48e3a
--- /dev/null
+++ b/src/SemanticScuttle/Model/RemoteUser.php
@@ -0,0 +1,48 @@
+<?php
+/**
+ * SemanticScuttle - your social bookmark manager.
+ *
+ * PHP version 5.
+ *
+ * @category Bookmarking
+ * @package SemanticScuttle
+ * @author Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net>
+ * @author Christian Weiske <cweiske@cweiske.de>
+ * @author Eric Dane <ericdane@users.sourceforge.net>
+ * @license GPL http://www.gnu.org/licenses/gpl.html
+ * @link http://sourceforge.net/projects/semanticscuttle
+ */
+
+/**
+ * Remote User helper methods.
+ *
+ * @category Bookmarking
+ * @package SemanticScuttle
+ * @author Christian Weiske <cweiske@cweiske.de>
+ * @license GPL http://www.gnu.org/licenses/gpl.html
+ * @link http://sourceforge.net/projects/semanticscuttle
+ */
+class SemanticScuttle_Model_RemoteUser
+{
+ /**
+ * Returns the remote user's IP.
+ *
+ * @return string IP address. NULL if not found.
+ */
+ public static function getIp()
+ {
+ $ip = null;
+ if (getenv('REMOTE_ADDR')) {
+ $ip = getenv('REMOTE_ADDR');
+ } else if (getenv('HTTP_CLIENT_IP')) {
+ $ip = getenv('HTTP_CLIENT_IP');
+ } else if (getenv('HTTP_X_FORWARDED_FOR')) {
+ $ip = getenv('HTTP_X_FORWARDED_FOR');
+ }
+
+ return $ip;
+ }
+
+}
+
+?> \ No newline at end of file
diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php
index d5a63a3..4b51f35 100644
--- a/src/SemanticScuttle/Service/Bookmark.php
+++ b/src/SemanticScuttle/Service/Bookmark.php
@@ -12,6 +12,7 @@
* @license GPL http://www.gnu.org/licenses/gpl.html
* @link http://sourceforge.net/projects/semanticscuttle
*/
+require_once 'SemanticScuttle/Model/RemoteUser.php';
/**
* SemanticScuttle bookmark service.
@@ -453,14 +454,6 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
$address = $this->normalize($address);
- if (getenv('HTTP_CLIENT_IP')) {
- $ip = getenv('HTTP_CLIENT_IP');
- } else if (getenv('REMOTE_ADDR')) {
- $ip = getenv('REMOTE_ADDR');
- } else {
- $ip = getenv('HTTP_X_FORWARDED_FOR');
- }
-
/*
* Note that if date is NULL, then it's added with a date and
* time of now, and if it's present,
@@ -480,7 +473,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
// Set up the SQL insert statement and execute it.
$values = array(
'uId' => intval($sId),
- 'bIp' => $ip,
+ 'bIp' => SemanticScuttle_Model_RemoteUser::getIp(),
'bDatetime' => $datetime,
'bModified' => $datetime,
'bTitle' => $title,
@@ -570,15 +563,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
return false;
}
- // Get the client's IP address and the date; note that the date is in GMT.
- if (getenv('HTTP_CLIENT_IP'))
- $ip = getenv('HTTP_CLIENT_IP');
- else
- if (getenv('REMOTE_ADDR'))
- $ip = getenv('REMOTE_ADDR');
- else
- $ip = getenv('HTTP_X_FORWARDED_FOR');
-
+ // Get the the date; note that the date is in GMT.
$moddatetime = gmdate('Y-m-d H:i:s', time());
$address = $this->normalize($address);