summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan Prodromou <evan@status.net>2010-02-16 11:06:10 -0500
committerEvan Prodromou <evan@status.net>2010-02-16 11:06:10 -0500
commita8c2a8261e79dd2047caaa158e7c5609d9835449 (patch)
tree110d196625e6d248a6ca89e6f3eac37e510b44d7
parent813451c9f9aac0690019d936dea2bf9d37ca6c13 (diff)
move some nickname-guessing code to lib/util.php from OpenID
-rw-r--r--lib/util.php54
-rw-r--r--plugins/OpenID/finishopenidlogin.php47
2 files changed, 55 insertions, 46 deletions
diff --git a/lib/util.php b/lib/util.php
index 209dc2254..ae812e8cf 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -1007,7 +1007,6 @@ function common_enqueue_notice($notice)
if (Event::hasHandler('HandleQueuedNotice')) {
$transports[] = 'plugin';
}
-
$xmpp = common_config('xmpp', 'enabled');
@@ -1574,3 +1573,56 @@ function common_client_ip()
return array($proxy, $ip);
}
+
+function common_url_to_nickname($url)
+{
+ static $bad = array('query', 'user', 'password', 'port', 'fragment');
+
+ $parts = parse_url($url);
+
+ # If any of these parts exist, this won't work
+
+ foreach ($bad as $badpart) {
+ if (array_key_exists($badpart, $parts)) {
+ return null;
+ }
+ }
+
+ # We just have host and/or path
+
+ # If it's just a host...
+ if (array_key_exists('host', $parts) &&
+ (!array_key_exists('path', $parts) || strcmp($parts['path'], '/') == 0))
+ {
+ $hostparts = explode('.', $parts['host']);
+
+ # Try to catch common idiom of nickname.service.tld
+
+ if ((count($hostparts) > 2) &&
+ (strlen($hostparts[count($hostparts) - 2]) > 3) && # try to skip .co.uk, .com.au
+ (strcmp($hostparts[0], 'www') != 0))
+ {
+ return common_nicknamize($hostparts[0]);
+ } else {
+ # Do the whole hostname
+ return common_nicknamize($parts['host']);
+ }
+ } else {
+ if (array_key_exists('path', $parts)) {
+ # Strip starting, ending slashes
+ $path = preg_replace('@/$@', '', $parts['path']);
+ $path = preg_replace('@^/@', '', $path);
+ if (strpos($path, '/') === false) {
+ return common_nicknamize($path);
+ }
+ }
+ }
+
+ return null;
+}
+
+function common_nicknamize($str)
+{
+ $str = preg_replace('/\W/', '', $str);
+ return strtolower($str);
+}
diff --git a/plugins/OpenID/finishopenidlogin.php b/plugins/OpenID/finishopenidlogin.php
index d25ce696c..438a728d8 100644
--- a/plugins/OpenID/finishopenidlogin.php
+++ b/plugins/OpenID/finishopenidlogin.php
@@ -438,49 +438,7 @@ class FinishopenidloginAction extends Action
function urlToNickname($openid)
{
- static $bad = array('query', 'user', 'password', 'port', 'fragment');
-
- $parts = parse_url($openid);
-
- # If any of these parts exist, this won't work
-
- foreach ($bad as $badpart) {
- if (array_key_exists($badpart, $parts)) {
- return null;
- }
- }
-
- # We just have host and/or path
-
- # If it's just a host...
- if (array_key_exists('host', $parts) &&
- (!array_key_exists('path', $parts) || strcmp($parts['path'], '/') == 0))
- {
- $hostparts = explode('.', $parts['host']);
-
- # Try to catch common idiom of nickname.service.tld
-
- if ((count($hostparts) > 2) &&
- (strlen($hostparts[count($hostparts) - 2]) > 3) && # try to skip .co.uk, .com.au
- (strcmp($hostparts[0], 'www') != 0))
- {
- return $this->nicknamize($hostparts[0]);
- } else {
- # Do the whole hostname
- return $this->nicknamize($parts['host']);
- }
- } else {
- if (array_key_exists('path', $parts)) {
- # Strip starting, ending slashes
- $path = preg_replace('@/$@', '', $parts['path']);
- $path = preg_replace('@^/@', '', $path);
- if (strpos($path, '/') === false) {
- return $this->nicknamize($path);
- }
- }
- }
-
- return null;
+ return common_url_to_nickname($openid);
}
function xriToNickname($xri)
@@ -510,7 +468,6 @@ class FinishopenidloginAction extends Action
function nicknamize($str)
{
- $str = preg_replace('/\W/', '', $str);
- return strtolower($str);
+ return common_nicknamize($str);
}
}