username detection

This commit is contained in:
Christian Mehlmauer
2013-02-05 14:31:03 +01:00
parent 014048a8ac
commit 7f15753e4b
3 changed files with 180 additions and 3 deletions

View File

@@ -43,7 +43,7 @@ module WpUsernames
nickname = get_nickname_from_url(url)
elsif response.code == 200 # username in body?
# get the username from the author feed URL
username = response.body[%r{/author/([^/\b]+)/?}i, 1]
username = get_username_from_response(response)
nickname = get_nickname_from_response(response)
end
@@ -76,6 +76,16 @@ module WpUsernames
nickname
end
def get_username_from_response(resp)
# Feed URL with Permalinks
username = resp.body[%r{/author/([^/\b]+)/?}i, 1]
if username.nil?
# No Permalinks
username = resp.body[%r{<body class="archive author author-([^\s]+) author-(\d+)}i, 1]
end
username
end
def extract_nickname_from_body(body)
body[%r{<title>([^<]*)</title>}i, 1]
end