Skip to content

Commit

Permalink
Use homeURL instead of hostName to show the blog address. WordPress c…
Browse files Browse the repository at this point in the history
…an be installed in a sub-directory, and so the host name will be the same for two subdir installations on the same host.
  • Loading branch information
daniloercoli committed Sep 15, 2015
1 parent b534e1d commit 55037d2
Showing 1 changed file with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ public class BlogUtils {
public int compare(Object blog1, Object blog2) {
Map<String, Object> blogMap1 = (Map<String, Object>) blog1;
Map<String, Object> blogMap2 = (Map<String, Object>) blog2;
String blogName1 = getBlogNameOrHostNameFromAccountMap(blogMap1);
String blogName2 = getBlogNameOrHostNameFromAccountMap(blogMap2);
String blogName1 = getBlogNameOrHomeURLFromAccountMap(blogMap1);
String blogName2 = getBlogNameOrHomeURLFromAccountMap(blogMap2);
return blogName1.compareToIgnoreCase(blogName2);
}
};

/**
* Return a blog name or blog url (host part only) if trimmed name is an empty string
* Return a blog name or blog home URL if trimmed name is an empty string
*/
public static String getBlogNameOrHostNameFromAccountMap(Map<String, Object> account) {
public static String getBlogNameOrHomeURLFromAccountMap(Map<String, Object> account) {
String blogName = getBlogNameFromAccountMap(account);
if (blogName.trim().length() == 0) {
blogName = StringUtils.getHost(MapUtils.getMapStr(account, "url"));
blogName = BlogUtils.getHomeURLOrHostNameFromAccountMap(account);
}
return blogName;
}
Expand All @@ -33,9 +33,18 @@ public static String getBlogNameFromAccountMap(Map<String, Object> account) {
}

/**
* Return blog url (host part only) if trimmed name is an empty string
* Return the blog home URL setting or the host name if home URL is an empty string.
*/
public static String getHostNameFromAccountMap(Map<String, Object> account) {
return StringUtils.getHost(MapUtils.getMapStr(account, "url"));
public static String getHomeURLOrHostNameFromAccountMap(Map<String, Object> account) {
String homeURL = MapUtils.getMapStr(account, "homeURL").replace("http://", "").replace("https://", "").trim();
if (homeURL.endsWith("/")) {
homeURL = homeURL.substring(0, homeURL.length() -1);
}

if (homeURL.length() == 0) {
return StringUtils.getHost(MapUtils.getMapStr(account, "url"));
}

return homeURL;
}
}

0 comments on commit 55037d2

Please sign in to comment.